From 749a4c57bbf3f40729169f8205f67af9049522c6 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Sun, 22 Apr 2018 11:03:35 -0400 Subject: [PATCH] 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. --- src/fields/core/fieldSubmit.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fields/core/fieldSubmit.vue b/src/fields/core/fieldSubmit.vue index 346e983d..5d46b48a 100644 --- a/src/fields/core/fieldSubmit.vue +++ b/src/fields/core/fieldSubmit.vue @@ -12,10 +12,13 @@ methods: { onClick($event) { if (this.schema.validateBeforeSubmit === true) { + // prevent a
from having it's submit event triggered + // when we have to validate data first + $event.preventDefault(); let errors = this.$parent.validate(); let handleErrors = (errors) => { if(!isEmpty(errors) && isFunction(this.schema.onValidationError)) { - this.schema.onValidationError(this.model, this.schema, errors); + this.schema.onValidationError(this.model, this.schema, errors, $event); } else if (isFunction(this.schema.onSubmit)) { this.schema.onSubmit(this.model, this.schema, $event); } @@ -27,6 +30,8 @@ handleErrors(errors); } } else if (isFunction(this.schema.onSubmit)) { + // if we aren't validating, just pass the onSubmit handler the $event + // so it can be handled there this.schema.onSubmit(this.model, this.schema, $event); } }