function theme_webform_number in Webform 7.3
Same name and namespace in other branches
- 6.3 components/number.inc \theme_webform_number()
- 7.4 components/number.inc \theme_webform_number()
Theme function to render a number component.
1 theme call to theme_webform_number()
- webform_element_info in ./
webform.module - Implements hook_element_info().
File
- components/
number.inc, line 222 - Webform module number component.
Code
function theme_webform_number($variables) {
$element = $variables['element'];
// This IF statement is mostly in place to allow our tests to set type="text"
// because SimpleTest does not support type="number".
if (!isset($element['#attributes']['type'])) {
$element['#attributes']['type'] = 'number';
}
// Step property *must* be a full number with 0 prefix if a decimal.
if (!empty($element['#step']) && !is_int($element['#step'] * 1)) {
$decimals = strlen($element['#step']) - strrpos($element['#step'], '.') - 1;
$element['#step'] = sprintf('%1.' . $decimals . 'F', $element['#step']);
}
// If the number is not an integer and step is undefined/empty, set the "any"
// value to allow any decimal.
if (empty($element['#integer']) && empty($element['#step'])) {
$element['#step'] = 'any';
}
elseif ($element['#integer'] && empty($element['#step'])) {
$element['#step'] = 1;
}
// Convert properties to attributes on the element if set.
foreach (array(
'id',
'name',
'value',
'size',
'min',
'max',
'step',
) as $property) {
if (isset($element['#' . $property]) && $element['#' . $property] !== '') {
$element['#attributes'][$property] = $element['#' . $property];
}
}
_form_set_class($element, array(
'form-text',
'form-number',
));
return '<input' . drupal_attributes($element['#attributes']) . ' />';
}