Skip to content

Commit

Permalink
fix: form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
14nrv committed Sep 30, 2018
1 parent 6863c5b commit 176bf56
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,24 @@ export default {
const allControlRequire = this.allControls.filter(({ item }) => item.isRequired === undefined)
const isAllControlRequireWithValue = allControlRequire.every(({ value }) => !!value)
const isFormValuesEmpty = Object.values(this.formValues).every(x => x === undefined)
return isAllControlRequireWithValue && !isFormValuesEmpty
const hasError = !!this.$validator.errors.items.length
return isAllControlRequireWithValue && !isFormValuesEmpty && !hasError
}
},
methods: {
async beforeSubmit (ev) {
const result = await this.$validator.validateAll(this.formName)
result && this.isFormValid && this.$root.$emit('formSubmitted', {
let isValidated = false
await this.$validator.validateAll(this.formName)
.then(result => { isValidated = result })
isValidated && this.isFormValid && this.emitValues({
formName: this.formName,
values: this.formValues
})
result && this.resetForm(ev)
isValidated && this.resetForm(ev)
},
emitValues (data) {
this.$root.$emit('formSubmitted', data)
},
resetFormValues () {
this.allControls.map(x => { x.value = '' })
Expand Down

0 comments on commit 176bf56

Please sign in to comment.