]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #397 and Refs #2396 Can suppress the default value for both input/checkbox...
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 23 Nov 2010 00:50:25 +0000 (00:50 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 23 Nov 2010 00:50:25 +0000 (00:50 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7424 36083f99-b078-4883-b0ff-0f9b5a30f544

views/default/input/checkbox.php
views/default/input/checkboxes.php

index 32bc323fddf4b1e3004ec862b1fff1140a93214a..e70064ddbca73eda4b17503cccf4007808100450 100644 (file)
@@ -1,10 +1,17 @@
 <?php
 /**
  * Elgg checkbox input
- * Displays a checkbox input field
+ * 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(
@@ -13,6 +20,17 @@ $defaults = array(
 
 $vars = array_merge($defaults, $vars);
 
+if (isset($vars['default'])) {
+       $default = $vars['default'];
+       unset($vars['default']);
+} else {
+       $default = 0;
+}
+
+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
index 46254633bfa0315a8444f24ad91f90201dfff1ce..94f01867c477b7fb42be52c87e1e1f352d3ae950 100644 (file)
@@ -5,19 +5,23 @@
  * NB: 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=internalname])
+ *     $('input[type=checkbox][name=internalname]')
  *
  * @package Elgg
  * @subpackage Core
  *
- * @uses string $vars['internalname'] 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['internalid'] 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.
- * @uses bool $vars['disabled'] Make all input elements disabled. Optional.
- * @uses string $vars['value'] The current value. Optional.
- * @uses string $vars['class'] The class of each input element. Optional.
- * @uses string $vars['js'] Any Javascript to enter into the input tag. Optional.
+ * @uses string $vars['internalname'] 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['internalid']   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']        The class of each input element. Optional.
+ * @uses string $vars['js']           Any Javascript to enter into the input tag. Optional.
  *
  */
 
@@ -38,11 +42,11 @@ $js = (isset($vars['js'])) ? $vars['js'] : '';
 
 if ($options) {
        // include a default value so if nothing is checked 0 will be passed.
-       if ($internalname) {
+       if ($internalname && $default !== FALSE) {
                echo "<input type=\"hidden\" name=\"$internalname\" value=\"$default\">";
        }
 
-       foreach($options as $label => $option) {
+       foreach ($options as $label => $option) {
                // @hack - This sorta checks if options is not an assoc array and then
                // ignores the label (because it's just the index) and sets the value ($option)
                // as the label.
@@ -58,6 +62,7 @@ if ($options) {
                        'disabled' => $disabled,
                        'id' => $id,
                        'js' => $js,
+                       'default' => false,
                );
                
                if ($class) {