Commit 5d85ae9f authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

Issue #1513922 by Laurent_: Added Trigger validation on document ready.

parent c53dbe5f
......@@ -19,6 +19,7 @@
Drupal.myClientsideValidation.bindForms();
}
}
jQuery.event.trigger('clientsideValidationInitialized')
}
}
......
; $Id:
name = Clientside Validation IFE
description = Display server side generated errors as if they were generated by clientside validation.
core = 7.x
package = Clientside Validation
files[] = clientside_validation_ife.module
files[] = clientside_validation_ife.js
dependencies[] = clientside_validation
dependencies[] = ife
(function ($) {
Drupal.behaviors.clientsideValidationIfe = {
attach: function (context) {
$(document).bind('clientsideValidationInitialized', function (event, formid){
jQuery.each(Drupal.myClientsideValidation.forms, function (formid) {
Drupal.myClientsideValidation.validators[formid].showErrors(Drupal.settings.clientsideValidation.forms[formid].serverSideErrors);
});
});
}
}
})(jQuery);
\ No newline at end of file
<?php
/**
* @file
*
*/
/**
* Implements hook_form_FORM_ID_alter().
*/
function clientside_validation_ife_form_ife_settings_form_alter(&$form) {
$form['general_settings']['ife_display']['#options'][] = t('Show error messages through Clientside Validation');
foreach (element_children($form['form_ids']) as $child) {
$form['form_ids'][$child]['display']['#options'][] = t('Show error messages through Clientside Validation');
}
}
/**
* Implements hook_clientside_validation_form_alter().
*/
function clientside_validation_ife_clientside_validation_form_alter(&$form, &$form_state, &$js_rules) {
$form['#validate'][] = 'clientside_validation_ife_validator';
}
function clientside_validation_ife_validator($form, $form_state) {
static $settings = array();
if (!isset($settings[$form['#form_id']])) {
$settings[$form['#form_id']] = array();
if (isset($form['#ife_display']) && $form['#ife_display'] == 3) {
// recurse through the form elements
clientside_validation_ife_recurse_elements($form, $form['#form_id'], $settings);
}
}
$js_settings['clientsideValidation']['forms'][$form['#id']]['serverSideErrors'] = $settings[$form['#form_id']];
drupal_add_js(drupal_get_path('module', 'clientside_validation_ife') . '/clientside_validation_ife.js');
drupal_add_js($js_settings, 'setting');
}
function clientside_validation_ife_recurse_elements($element, $form_id, &$settings) {
foreach (element_children($element) as $key) {
if (isset($element[$key]) && $element[$key]) {
clientside_validation_ife_recurse_elements($element[$key], $form_id, $settings);
}
}
if (isset($element['#name'])) {
$settings[$form_id][$element['#name']] = ife_errors('get', $element['#id']);
// Delete the message so IFE won't display it again.
ife_errors('set', $element['#id'], NULL);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment