pluf2

pluf2 Commit Details


Date:2010-04-02 09:35:15 (14 years 8 months ago)
Author:Thomas Riché
Branch:master
Commit:8e26c8fc0372f9a5c9eba2e84d6b16a2bebbc16e
Parents: 6523fb7bf6b52a36a2f4cffea777992938e73366
Message:Added optgroup support in the select form widget.

Changes:

File differences

src/Pluf/Form/Widget/SelectInput.php
2222
2323
2424
25
25
2626
2727
2828
......
5353
5454
5555
56
57
58
59
60
61
62
63
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
6474
6575
6676
6777
68
78
# ***** END LICENSE BLOCK ***** */
/**
* Simple checkbox.
* Simple checkbox with grouping.
*/
class Pluf_Form_Widget_SelectInput extends Pluf_Form_Widget
{
}
$final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
$output[] = '<select'.Pluf_Form_Widget_Attrs($final_attrs).'>';
$choices = $this->choices + $choices;
foreach ($choices as $option_label=>$option_value) {
$selected = ($option_value == $value) ? ' selected="selected"':'';
$output[] = sprintf('<option value="%s"%s>%s</option>',
htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'),
$selected,
htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
$groups = $this->choices + $choices;
foreach($groups as $option_group => $c) {
if (!is_array($c)) {
$subchoices = array($option_group => $c);
} else {
$output[] = '<optgroup label="'.htmlspecialchars($option_group, ENT_COMPAT, 'UTF-8').'">';
$subchoices = $c;
}
foreach ($subchoices as $option_label=>$option_value) {
$selected = ($option_value == $value) ? ' selected="selected"':'';
$output[] = sprintf('<option value="%s"%s>%s</option>',
htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'),
$selected,
htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
}
if (is_array($c)) {
$output[] = '</optgroup>';
}
}
$output[] = '</select>';
return new Pluf_Template_SafeString(implode("\n", $output), true);
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05145s using 13 queries.