Skip to content

Commit 73a08c1

Browse files
authored
Merge pull request #443 from zoul0813/feature/434-validateBeforeSubmit
closes #434, #408 - added $event to onValidationError
2 parents 2cf4a47 + 749a4c5 commit 73a08c1

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)