Development

Changeset 1432

You must first sign up to be able to contribute.

Changeset 1432

Show
Ignore:
Timestamp:
06/13/06 14:01:15 (2 years ago)
Author:
fabien
Message:

Updated options_for_select() to automatically detect arrays as <optgroup> tags for easy nesting. (closes #561 - patch from slickrick)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/helper/FormHelper.php

    r1415 r1432  
    6767  foreach ($options as $key => $value) 
    6868  { 
    69     $option_options = array('value' => $key); 
    70     if ( 
    71         isset($selected) 
    72         && 
    73         (is_array($selected) && in_array(strval($key), $valid, true)) 
    74         || 
    75         (strval($key) == strval($selected)) 
    76        ) 
    77     { 
    78       $option_options['selected'] = 'selected'; 
    79     } 
    80  
    81     $html .= content_tag('option', $value, $option_options)."\n"; 
     69    if (is_array($value)) 
     70    { 
     71      $optgroup_html_options = $html_options; 
     72      unset($optgroup_html_options['include_custom']); 
     73      unset($optgroup_html_options['include_blank']); 
     74      $html .= content_tag('optgroup', options_for_select($value, $selected, $optgroup_html_options), array('label' => $key)); 
     75    } 
     76    else  
     77    { 
     78      $option_options = array('value' => $key); 
     79       
     80      if ( 
     81          isset($selected) 
     82          && 
     83          (is_array($selected) && in_array(strval($key), $valid, true)) 
     84          || 
     85          (strval($key) == strval($selected)) 
     86         ) 
     87      { 
     88        $option_options['selected'] = 'selected'; 
     89      } 
     90 
     91      $html .= content_tag('option', $value, $option_options)."\n"; 
     92    } 
    8293  } 
    8394