Adds support for new errors
prop on the Formulate element that passes errors down to child elements. Also forms no longer prevent submission if they only have local errors. This can be changed with a prevent="all"
prop on the Formulate element.
This commit is contained in:
parent
d4443a1e2c
commit
46ac900f0e
16
dist/index.js
vendored
16
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<form
|
||||
@submit.prevent="submit"
|
||||
class="formulate-element"
|
||||
class="formulate-form"
|
||||
>
|
||||
<slot />
|
||||
</form>
|
||||
@ -34,6 +34,14 @@ export default {
|
||||
showErrors: {
|
||||
type: [Boolean, Object],
|
||||
default: () => ({})
|
||||
},
|
||||
errors: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
prevent: {
|
||||
type: String,
|
||||
default: 'validation'
|
||||
}
|
||||
},
|
||||
data () {
|
||||
@ -49,10 +57,13 @@ export default {
|
||||
hasErrors () {
|
||||
return this.$store.getters[`${this.m}hasErrors`][this.name] || false
|
||||
},
|
||||
hasValidationErrors () {
|
||||
return this.$store.getters[`${this.m}hasValidationErrors`][this.name] || false
|
||||
},
|
||||
values () {
|
||||
return cloneDeep(this.$store.getters[`${this.m}formValues`][this.name] || {})
|
||||
},
|
||||
errors () {
|
||||
storeErrors () {
|
||||
return this.$store.getters[`${this.m}formErrors`][this.name] || {}
|
||||
},
|
||||
validationErrors () {
|
||||
@ -134,12 +145,12 @@ export default {
|
||||
}))
|
||||
},
|
||||
submit () {
|
||||
if (this.hasErrors) {
|
||||
if ((this.prevent === 'validation' && this.hasValidationErrors) || (this.prevent === 'any' && this.hasErrors)) {
|
||||
this.forceErrors = true
|
||||
} else {
|
||||
this.$emit('submit', Object.assign({}, this.values))
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -229,10 +229,13 @@ export default {
|
||||
return this.form.validationErrors[this.name] || []
|
||||
},
|
||||
storeErrors () {
|
||||
return this.form.storeErrors[this.name] || []
|
||||
},
|
||||
formErrors () {
|
||||
return this.form.errors[this.name] || []
|
||||
},
|
||||
localAndValidationErrors () {
|
||||
return this.errors.concat(this.validationErrors)
|
||||
return this.errors.concat(this.validationErrors).concat(this.formErrors)
|
||||
},
|
||||
shouldShowErrors () {
|
||||
let show = this.form.shouldShowErrors
|
||||
|
@ -36,6 +36,11 @@ export const formulateGetters = (moduleName = '', getters = {}) => Object.assign
|
||||
return map(state.errors, (form, errors) => {
|
||||
return reduce(errors, (hasErrors, field, errors) => hasErrors || !!errors.length, false)
|
||||
})
|
||||
},
|
||||
hasValidationErrors (state) {
|
||||
return map(state.validationErrors, (form, errors) => {
|
||||
return reduce(errors, (hasErrors, field, errors) => hasErrors || !!errors.length, false)
|
||||
})
|
||||
}
|
||||
}, getters)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user