aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-25 18:54:05 +0000
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-25 18:54:05 +0000
commit4e5d14ee2638dd6c9b22baf67d880787fa6085e4 (patch)
treedff5c5b0c673b717a4fb1689e83be434483bd231
parent5eef9adfea09ef6c913069e8eff8c88cb8a02a04 (diff)
downloadelgg-4e5d14ee2638dd6c9b22baf67d880787fa6085e4.tar.gz
elgg-4e5d14ee2638dd6c9b22baf67d880787fa6085e4.tar.bz2
Updated input/checkboxes code in installation viewtype
git-svn-id: http://code.elgg.org/elgg/trunk@8467 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--views/installation/input/checkbox.php33
-rw-r--r--views/installation/input/checkboxes.php94
2 files changed, 97 insertions, 30 deletions
diff --git a/views/installation/input/checkbox.php b/views/installation/input/checkbox.php
new file mode 100644
index 000000000..898fe8458
--- /dev/null
+++ b/views/installation/input/checkbox.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Elgg checkbox input
+ * Displays a checkbox input tag
+ *
+ * @package Elgg
+ * @subpackage Core
+ *
+ *
+ * Pass input tag attributes as key value pairs. For a list of allowable
+ * attributes, see http://www.w3schools.com/tags/tag_input.asp
+ *
+ * @uses mixed $vars['default'] The default value to submit if not checked.
+ * Optional, defaults to 0. Set to false for no default.
+ */
+
+$defaults = array(
+ 'class' => 'elgg-input-checkbox',
+ 'default' => 0,
+);
+
+$vars = array_merge($defaults, $vars);
+
+$default = $vars['default'];
+unset($vars['default']);
+
+if (isset($vars['name']) && $default !== false) {
+ echo "<input type=\"hidden\" name=\"{$vars['name']}\" value=\"$default\"/>";
+}
+
+?>
+
+<input type="checkbox" <?php echo elgg_format_attributes($vars); ?> /> \ No newline at end of file
diff --git a/views/installation/input/checkboxes.php b/views/installation/input/checkboxes.php
index 164509831..c78fe4db0 100644
--- a/views/installation/input/checkboxes.php
+++ b/views/installation/input/checkboxes.php
@@ -3,46 +3,80 @@
* Elgg checkbox input
* Displays a checkbox input field
*
+ * @note This also includes a hidden input with the same name as the checkboxes
+ * to make sure something is sent to the server. The default value is 0.
+ * If using JS, be specific to avoid selecting the hidden default value:
+ * $('input[type=checkbox][name=name]')
+ *
+ * @warning Passing integers as labels does not currently work due to a
+ * deprecated hack that will be removed in Elgg 1.9. To use integer labels,
+ * the labels must be character codes: 1 would be &#0049;
+ *
* @package Elgg
* @subpackage Core
*
- * @uses $vars['value'] The current value, if any
- * @uses $vars['js'] Any Javascript to enter into the input tag
- * @uses $vars['name'] The name of the input field
- * @uses $vars['options'] An array of strings representing the options for the checkbox field
+ * @uses string $vars['name'] The name of the input fields
+ * (Forced to an array by appending [])
+ * @uses array $vars['options'] An array of strings representing the
+ * label => option for the each checkbox field
+ * @uses string $vars['id'] The id for each input field. Optional.
+ * (Only use this with a single value.)
+ * @uses string $vars['default'] The default value to send if nothing is checked.
+ * Optional, defaults to 0. Set to FALSE for no default.
+ * @uses bool $vars['disabled'] Make all input elements disabled. Optional.
+ * @uses string $vars['value'] The current value. Optional.
+ * @uses string $vars['class'] Additional class of the list. Optional.
+ * @uses string $vars['align'] 'horizontal' or 'vertical' Default: 'vertical'
*
*/
-$class = $vars['class'];
-if (!$class) {
- $class = "elgg-input-checkboxes";
+$additional_class = elgg_extract('class', $vars);
+$align = elgg_extract('align', $vars, 'vertical');
+$value = (isset($vars['value'])) ? $vars['value'] : NULL;
+$value_array = (is_array($value)) ? array_map('elgg_strtolower', $value) : array(elgg_strtolower($value));
+$name = (isset($vars['name'])) ? $vars['name'] : '';
+$options = (isset($vars['options']) && is_array($vars['options'])) ? $vars['options'] : array();
+$default = (isset($vars['default'])) ? $vars['default'] : 0;
+
+$id = (isset($vars['id'])) ? $vars['id'] : '';
+$disabled = (isset($vars['disabled'])) ? $vars['disabled'] : FALSE;
+$js = (isset($vars['js'])) ? $vars['js'] : '';
+
+$class = "elgg-input-checkboxes elgg-$align";
+if ($additional_class) {
+ $class = " $additional_class";
}
-foreach($vars['options'] as $label => $option) {
- //if (!in_array($option,$vars['value'])) {
- if (is_array($vars['value'])) {
- if (!in_array($option,$vars['value'])) {
- $selected = "";
- } else {
- $selected = "checked = \"checked\"";
+if ($options && count($options) > 0) {
+ // include a default value so if nothing is checked 0 will be passed.
+ if ($name && $default !== FALSE) {
+ echo "<input type=\"hidden\" name=\"$name\" value=\"$default\" />";
+ }
+
+ echo "<ul class=\"$class\">";
+ foreach ($options as $label => $option) {
+ // @deprecated 1.8 Remove in 1.9
+ if (is_integer($label)) {
+ elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/checkboxes', 1.8);
+ $label = $option;
}
- } else {
- if ($option != $vars['value']) {
- $selected = "";
- } else {
- $selected = "checked = \"checked\"";
+
+ $input_vars = array(
+ 'checked' => in_array(elgg_strtolower($option), $value_array),
+ 'value' => $option,
+ 'disabled' => $disabled,
+ 'id' => $id,
+ 'js' => $js,
+ 'default' => false,
+ );
+
+ if ($name) {
+ $input_vars['name'] = "{$name}[]";
}
- }
-
- // handle indexed array where label is not specified
- // @todo deprecate in Elgg 1.8
- if (is_integer($label)) {
- $label = $option;
- }
+
+ $input = elgg_view('input/checkbox', $input_vars);
- $disabled = "";
- if ($vars['disabled']) {
- $disabled = ' disabled="yes" ';
+ echo "<li><label>{$input}{$label}</label></li>";
}
- echo "<label><input type=\"checkbox\" $disabled {$vars['js']} name=\"{$vars['name']}[]\" {$selected} value=\"".htmlentities($option, ENT_QUOTES, 'UTF-8')."\" {$selected} class=\"$class\" />{$label}</label><br />";
+ echo '</ul>';
} \ No newline at end of file