function maxlength_pre_render in Maxlength 7.3
Pre render function to set maxlength attributes.
1 call to maxlength_pre_render()
- maxlength_form_alter in ./
maxlength.module - Implements hook_form_alter().
1 string reference to 'maxlength_pre_render'
- maxlength_element_info_alter in ./
maxlength.module - Implements hook_element_info_alter().
File
- ./
maxlength.module, line 49 - Limit the number of characters in textfields and textareas and shows the amount of characters left.
Code
function maxlength_pre_render($element) {
if ((isset($element['#maxlength']) && $element['#maxlength'] > 0 || isset($element['#attributes']['maxlength']) && $element['#attributes']['maxlength'] > 0) && isset($element['#maxlength_js']) && $element['#maxlength_js'] === TRUE) {
if ($element['#type'] == 'textarea' && !isset($element['#attributes']['maxlength'])) {
$element['#attributes']['maxlength'] = $element['#maxlength'];
}
$element['#attributes']['class'][] = 'maxlength';
$element['#attached']['js'][] = drupal_get_path('module', 'maxlength') . '/js/maxlength.js';
}
return $element;
}