function _webform_number_select_options in Webform 6.3
Same name and namespace in other branches
- 7.4 components/number.inc \_webform_number_select_options()
- 7.3 components/number.inc \_webform_number_select_options()
Generate select list options.
1 call to _webform_number_select_options()
- _webform_render_number in components/
number.inc - Implements _webform_render_component().
File
- components/
number.inc, line 718 - Webform module number component.
Code
function _webform_number_select_options($component) {
$options = array();
$step = abs($component['extra']['step']);
// Step is optional and defaults to 1.
$step = empty($step) ? 1 : $step;
// Generate list in correct direction.
$min = $component['extra']['min'];
$max = $component['extra']['max'];
$flipped = FALSE;
if ($max < $min) {
$min = $component['extra']['max'];
$max = $component['extra']['min'];
$flipped = TRUE;
}
for ($f = $min; $f <= $max; $f += $step) {
$options[$f . ''] = $f . '';
}
// TODO: HTML5 browsers apparently do not include the max value if it does
// not line up with step. Restore this if needed in the future.
// Add end limit if it's been skipped due to step.
//if (end($options) != $max) {
// $options[$f] = $max;
//}
if ($flipped) {
$options = array_reverse($options, TRUE);
}
// Apply requisite number formatting.
foreach ($options as $key => $value) {
$options[$key] = _webform_number_format($component, $value);
}
return $options;
}