Commit cd1aba7d authored by Jelle's avatar Jelle
Browse files

Issue #2056219 by inventlogic: Fixed General problem with drupal AJAX requests...

Issue #2056219 by inventlogic: Fixed General problem with drupal AJAX requests prevented by clientside validation.
parent f95e80cd
......@@ -43,27 +43,6 @@
}
}
// Set validation for ajax forms
for (var ajax_el in Drupal.settings.ajax) {
if (typeof Drupal.ajax[ajax_el] !== 'undefined' && Drupal.ajax[ajax_el].validate_first) {
var ajax_elem = ajax_el;
var origBeforeSubmit = Drupal.ajax[ajax_elem].options.beforeSubmit;
Drupal.ajax[ajax_elem].options.beforeSubmit = function (form_values, element, options) {
var ret = origBeforeSubmit(form_values, element, options);
// If this function didn't return anything, just set the return value to true.
// If it did return something, allow it to prevent submit if necessary.
if (typeof ret === 'undefined') {
ret = true;
}
ret = ret && Drupal.myClientsideValidation.validators[element.attr('id')].form();
if (!ret) {
Drupal.ajax[ajax_elem].ajaxing = false;
}
return ret;
};
}
}
/**
* Let other modules know we are ready.
* @event clientsideValidationInitialized
......@@ -1353,27 +1332,28 @@
// Set validation for ctools modal forms
for (var ajax_el in Drupal.ajax) {
if (typeof Drupal.ajax[ajax_el] !== 'undefined') {
var origBeforeSubmit = Drupal.ajax[ajax_el].options.beforeSubmit;
Drupal.ajax[ajax_el].options.beforeSubmit = function (form_values, element, options) {
var ret = origBeforeSubmit(form_values, element, options);
// If this function didn't return anything, just set the return value to true.
// If it did return something, allow it to prevent submit if necessary.
if (typeof ret === 'undefined') {
ret = true;
}
var id = element.is('form') ? element.attr('id') : element.closest('form').attr('id');
if (id && Drupal.myClientsideValidation.validators[id]) {
Drupal.myClientsideValidation.validators[id].onsubmit = false;
ret = ret && Drupal.myClientsideValidation.validators[id].form();
if (!ret) {
Drupal.ajax[ajax_el].ajaxing = false;
if (!jQuery(Drupal.ajax[ajax_el].element).hasClass('cancel')) {
var origBeforeSubmit = Drupal.ajax[ajax_el].options.beforeSubmit;
Drupal.ajax[ajax_el].options.beforeSubmit = function (form_values, element, options) {
var ret = origBeforeSubmit(form_values, element, options);
// If this function didn't return anything, just set the return value to true.
// If it did return something, allow it to prevent submit if necessary.
if (typeof ret === 'undefined') {
ret = true;
}
}
return ret;
};
var id = element.is('form') ? element.attr('id') : element.closest('form').attr('id');
if (id && Drupal.myClientsideValidation.validators[id]) {
Drupal.myClientsideValidation.validators[id].onsubmit = false;
ret = ret && Drupal.myClientsideValidation.validators[id].form();
if (!ret) {
Drupal.ajax[ajax_el].ajaxing = false;
}
}
return ret;
};
}
}
}
}
}
};
})(jQuery);
......@@ -17,6 +17,9 @@ function clientside_validation_form_after_build_recurse($form_id, &$form, &$form
$element = &$form[$item];
if (isset($element['#type'])) {
clientside_validation_regular($form_id, $element, $js_rules, $form_state);
if ($element['#type'] == 'submit' && isset($element['#limit_validation_errors']) && empty($element['#limit_validation_errors']) && $element['#limit_validation_errors'] !== FALSE) {
$element['#attributes']['class'][] = 'cancel';
}
}
if (isset($element['#element_validate']) && !empty($element['#element_validate'])) {
$context = array('type' => 'element_validate', 'functions' => $element['#element_validate']);
......
Markdown is supported
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