Skip to content

Commit dceecf4

Browse files
committed
preserve original submit event to keep track of the button the form was submitted with
1 parent b85214c commit dceecf4

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

Resources/public/js/FpJsFormValidator.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,21 @@ function FpJsCustomizeMethods() {
265265
//noinspection JSCheckFunctionSignatures
266266
FpJsFormValidator.each(this, function (item) {
267267
var element = item.jsFormValidator;
268-
if (event) {
269-
event.preventDefault();
270-
}
271268
element.validateRecursively();
272-
if (FpJsFormValidator.ajax.queue) {
273-
if (event) {
269+
var submitCallback = function () {
270+
element.onValidate.apply(element.domNode, [FpJsFormValidator.getAllErrors(element, {}), event]);
271+
if (!element.isValid() && event) {
274272
event.preventDefault();
275273
}
276-
FpJsFormValidator.ajax.callbacks.push(function () {
277-
element.onValidate.apply(element.domNode, [FpJsFormValidator.getAllErrors(element, {}), event]);
278-
if (element.isValid()) {
279-
element.submitForm.apply(item, [item]);
280-
}
281-
});
282-
} else {
283-
element.onValidate.apply(element.domNode, [FpJsFormValidator.getAllErrors(element, {}), event]);
284-
if (element.isValid()) {
274+
if (element.isValid() && !event) {
275+
// call submit only if the original submission was not trigerred by an event.
285276
element.submitForm.apply(item, [item]);
286277
}
278+
};
279+
if (FpJsFormValidator.ajax.queue) {
280+
FpJsFormValidator.ajax.callbacks.push(submitCallback);
281+
} else {
282+
submitCallback();
287283
}
288284
});
289285
};

0 commit comments

Comments
 (0)