Skip to content

Commit 749a4c5

Browse files
committed
closes #434, #408 - added $event to onValidationError and call preventDefault when onValidateBeforeSubmit is true
We can't prevent the submit after waiting for async validation, so we just prevent it before calling any validation and let the user manually submit the form in the `onSubmit` handler, if it validates.
1 parent 2cf4a47 commit 749a4c5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/fields/core/fieldSubmit.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
methods: {
1313
onClick($event) {
1414
if (this.schema.validateBeforeSubmit === true) {
15+
// prevent a <form /> from having it's submit event triggered
16+
// when we have to validate data first
17+
$event.preventDefault();
1518
let errors = this.$parent.validate();
1619
let handleErrors = (errors) => {
1720
if(!isEmpty(errors) && isFunction(this.schema.onValidationError)) {
18-
this.schema.onValidationError(this.model, this.schema, errors);
21+
this.schema.onValidationError(this.model, this.schema, errors, $event);
1922
} else if (isFunction(this.schema.onSubmit)) {
2023
this.schema.onSubmit(this.model, this.schema, $event);
2124
}
@@ -27,6 +30,8 @@
2730
handleErrors(errors);
2831
}
2932
} else if (isFunction(this.schema.onSubmit)) {
33+
// if we aren't validating, just pass the onSubmit handler the $event
34+
// so it can be handled there
3035
this.schema.onSubmit(this.model, this.schema, $event);
3136
}
3237
}

0 commit comments

Comments
 (0)