]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #972 checkboxes and radio input fields support horizontal and vertical alignments
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 14:02:11 +0000 (14:02 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 14:02:11 +0000 (14:02 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8154 36083f99-b078-4883-b0ff-0f9b5a30f544

views/default/css/elements/forms.php
views/default/input/checkboxes.php
views/default/input/radio.php

index 468c524a8d2ea043ef09b74d153eaa3d33610428..9d5ca6ffd3866e9ead65a4d16e18125734e67886 100644 (file)
@@ -58,6 +58,11 @@ input[type="radio"] {
        padding:0;
        border:none;
 }
+.elgg-input-checkboxes.elgg-horizontal li,
+.elgg-input-radio.elgg-horizontal li {
+       display: inline;
+       padding-left: 10px;
+}
 
 input[type="submit"],
 input[type="button"],
index 2ca48459d3f1a2f2c3d333b440a18914e144f518..85c44de54dc5c094432e788890bec345d151c3ac 100644 (file)
  *                                    (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
+ * @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.
+ * @uses string $vars['class']        Additional class of the list. Optional.
+ * @uses string $vars['align']       'horizontal' or 'vertical' Default: 'vertical'
  *
  */
 
-$class = (isset($vars['class'])) ? $vars['class'] : 'elgg-input-checkboxes';
+$additional_class = elgg_get_array_value('class', $vars);
+$align = elgg_get_array_value('align', $vars, 'vertical');
 $value = (isset($vars['value'])) ? $vars['value'] : NULL;
-$value_array = (is_array($value)) ? array_map('strtolower', $value) : array(strtolower($value));
+$value_array = (is_array($value)) ? array_map('elgg_strtolower', $value) : array(elgg_strtolower($value));
 $internalname = (isset($vars['internalname'])) ? $vars['internalname'] : '';
 $options = (isset($vars['options']) && is_array($vars['options'])) ? $vars['options'] : array();
 $default = (isset($vars['default'])) ? $vars['default'] : 0;
@@ -36,34 +37,33 @@ $id = (isset($vars['internalid'])) ? $vars['internalid'] : '';
 $disabled = (isset($vars['disabled'])) ? $vars['disabled'] : FALSE;
 $js = (isset($vars['js'])) ? $vars['js'] : '';
 
-if ($options) {
+$class = "elgg-input-checkboxes elgg-$align";
+if ($additional_class) {
+       $class = " $additional_class";
+}
+
+if ($options && count($options) > 0) {
        // include a default value so if nothing is checked 0 will be passed.
        if ($internalname && $default !== FALSE) {
                echo "<input type=\"hidden\" name=\"$internalname\" value=\"$default\" />";
        }
 
+       echo "<ul class=\"$class\">";
        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.
-               // Wow.
-               // @todo deprecate in Elgg 1.8
+               // @deprecated 1.8
                if (is_integer($label)) {
+                       elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/checkboxes', 1.8);
                        $label = $option;
                }
 
                $input_vars = array(
-                       'checked' => in_array(strtolower($option), $value_array),
+                       'checked' => in_array(elgg_strtolower($option), $value_array),
                        'value' => $option,
                        'disabled' => $disabled,
                        'id' => $id,
                        'js' => $js,
                        'default' => false,
                );
-               
-               if ($class) {
-                       $input_vars['class'] = $class;
-               }
 
                if ($internalname) {
                        $input_vars['name'] = "{$internalname}[]";
@@ -71,6 +71,7 @@ if ($options) {
                
                $input = elgg_view('input/checkbox', $input_vars);
 
-               echo "{$input}<label>{$label}</label><br />";
+               echo "<li>{$input}<label>{$label}</label></li>";
        }
+       echo '</ul>';
 }
\ No newline at end of file
index c897b48f18ebb3d9b460293d510545e095696242..924411aa89426898f6f0daa9fc781d4d9f3c4018 100644 (file)
@@ -6,18 +6,25 @@
  * @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['value']        The current value, if any
  * @uses $vars['internalname'] The name of the input field
- * @uses $vars['options'] An array of strings representing the options for the radio field as "label" => option
- *
+ * @uses $vars['options']      An array of strings representing the options for the
+ *                             radio field as "label" => option
+ * @uses $vars['class']        Additional class of the list. Optional.
+ * @uses $vars['align']       'horizontal' or 'vertical' Default: 'vertical'
  */
 
-$defaults = array(
-       'class' => 'elgg-input-radio',
-);
+$additional_class = elgg_get_array_value('class', $vars);
+$align = elgg_get_array_value('align', $vars, 'vertical');
+$class = "elgg-input-radio elgg-$align";
+if ($additional_class) {
+       $class = " $additional_class";
+       unset($vars['class']);
+}
 
-$vars = array_merge($defaults, $vars);
+if (isset($vars['align'])) {
+       unset($vars['align']);
+}
 
 $options = $vars['options'];
 unset($vars['options']);
@@ -25,18 +32,23 @@ unset($vars['options']);
 $value = $vars['value'];
 unset($vars['value']);
 
-foreach ($options as $label => $option) {
-       
-       $vars['checked'] = strtolower($option) != strtolower($vars['value']);
-       $vars['value'] = $option;
-       
-       $attributes = elgg_format_attributes($vars);
-       
-       // handle indexed array where label is not specified
-       // @todo deprecate in Elgg 1.8
-       if (is_integer($label)) {
-               $label = $option;
+if ($options && count($options) > 0) {
+       echo "<ul class=\"$class\">";
+       foreach ($options as $label => $option) {
+
+               $vars['checked'] = elgg_strtolower($option) != elgg_strtolower($vars['value']);
+               $vars['value'] = $option;
+
+               $attributes = elgg_format_attributes($vars);
+
+               // handle indexed array where label is not specified
+               // @deprecated 1.8
+               if (is_integer($label)) {
+                       elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/radio', 1.8);
+                       $label = $option;
+               }
+
+               echo "<li><label><input type=\"radio\" $attributes />$label</label></li>";
        }
-       
-       echo "<label><input type=\"radio\" $attributes />$label</label><br />";
-}
\ No newline at end of file
+       echo '</ul>';
+}