From dceecf445fa81372ad2854f5fb6c0e550bf7589c Mon Sep 17 00:00:00 2001 From: Richard Ejem Date: Wed, 2 Aug 2017 15:43:10 +0200 Subject: [PATCH] preserve original submit event to keep track of the button the form was submitted with --- Resources/public/js/FpJsFormValidator.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Resources/public/js/FpJsFormValidator.js b/Resources/public/js/FpJsFormValidator.js index dfc3e88..58fd94e 100644 --- a/Resources/public/js/FpJsFormValidator.js +++ b/Resources/public/js/FpJsFormValidator.js @@ -265,25 +265,21 @@ function FpJsCustomizeMethods() { //noinspection JSCheckFunctionSignatures FpJsFormValidator.each(this, function (item) { var element = item.jsFormValidator; - if (event) { - event.preventDefault(); - } element.validateRecursively(); - if (FpJsFormValidator.ajax.queue) { - if (event) { + var submitCallback = function () { + element.onValidate.apply(element.domNode, [FpJsFormValidator.getAllErrors(element, {}), event]); + if (!element.isValid() && event) { event.preventDefault(); } - FpJsFormValidator.ajax.callbacks.push(function () { - element.onValidate.apply(element.domNode, [FpJsFormValidator.getAllErrors(element, {}), event]); - if (element.isValid()) { - element.submitForm.apply(item, [item]); - } - }); - } else { - element.onValidate.apply(element.domNode, [FpJsFormValidator.getAllErrors(element, {}), event]); - if (element.isValid()) { + if (element.isValid() && !event) { + // call submit only if the original submission was not trigerred by an event. element.submitForm.apply(item, [item]); } + }; + if (FpJsFormValidator.ajax.queue) { + FpJsFormValidator.ajax.callbacks.push(submitCallback); + } else { + submitCallback(); } }); };