function theme_webform_number in Webform 7.4
Same name and namespace in other branches
- 6.3 components/number.inc \theme_webform_number()
- 7.3 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 243 - 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'])) {
// HTML5 number fields are no long used pending better browser support.
// See issues #2290029, #2202905.
// @code
// $element['#attributes']['type'] = 'number';
// @endcode
$element['#attributes']['type'] = 'text';
}
// Step property *must* be a full number with 0 prefix if a decimal.
if (!empty($element['#step']) && filter_var((double) $element['#step'], FILTER_VALIDATE_INT) === FALSE) {
$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']) . ' />';
}