function clientside_validation_add_validation in Clientside Validation 7.2
Same name and namespace in other branches
- 8.2 clientside_validation.module \clientside_validation_add_validation()
- 8 clientside_validation.module \clientside_validation_add_validation()
- 3.0.x clientside_validation.module \clientside_validation_add_validation()
- 2.0.x clientside_validation.module \clientside_validation_add_validation()
1 call to clientside_validation_add_validation()
File
- ./
clientside_validation.module, line 367 - Add client side validation to forms.
Code
function clientside_validation_add_validation(&$element, &$form_state, $form_id) {
$form_settings = clientside_validation_settings_current_form();
if (clientside_validation_should_validate($element)) {
$validators = clientside_validation_get_validators($element, $form_state);
foreach ($validators as $validator) {
$js_settings = array();
switch ($form_settings['validate_options']['rules_type']) {
case 'js_settings':
$js_settings = $validator
->getJavascriptSettings($element, $form_state);
break;
case 'data_attributes':
$validator
->setDataAttributes($element, $form_state);
$js_settings = $validator
->getJavascriptSettings($element, $form_state);
unset($js_settings['rules']);
unset($js_settings['messages']);
break;
}
$files = $validator
->jsFiles($element);
if ($js_settings) {
$element['#attached']['js'][] = array(
'data' => array(
'clientsideValidation' => array(
'forms' => array(
$form_id => $js_settings,
),
),
),
'type' => 'setting',
);
}
if ($files) {
foreach ($files as $file) {
$element['#attached']['js'][] = array(
'data' => $file,
'type' => 'file',
'scope' => 'footer',
);
}
}
}
return !empty($validators);
}
return FALSE;
}