Commit 905fbddc authored by Jelle's avatar Jelle
Browse files

Fix closure when changing ajax behaviors

parent d48555ce
......@@ -1352,28 +1352,31 @@
Drupal.behaviors.ZZZClientsideValidation = {
attach: function () {
function changeAjax(ajax_el) {
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;
}
}
return ret;
};
}
// Set validation for ctools modal forms
for (var ajax_el in Drupal.ajax) {
if (typeof Drupal.ajax[ajax_el] !== 'undefined') {
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;
}
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;
};
changeAjax(ajax_el);
}
}
}
......
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