Fixes a race condition that could add validation errors for fields that had been removed
This commit is contained in:
parent
6b19a973a8
commit
55368defd1
6
dist/index.js
vendored
6
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -48,7 +48,8 @@ export default {
|
||||
return {
|
||||
parentIdentifier: 'vue-formulate-wrapper-element',
|
||||
forceErrors: null,
|
||||
fieldInitials: {}
|
||||
fieldInitials: {},
|
||||
whenFinishedValidating: Promise.resolve()
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -103,13 +104,16 @@ export default {
|
||||
methods: {
|
||||
registerField (field, data) {
|
||||
this.$store.commit(`${this.m}setFieldMeta`, {form: this.name, field, data})
|
||||
this.$store.commit(`${this.m}setFieldValue`, {
|
||||
field,
|
||||
value: this.mergedInitial.hasOwnProperty(field) ? this.mergedInitial[field] : undefined,
|
||||
form: this.name
|
||||
})
|
||||
if (data.type !== 'submit') {
|
||||
this.$store.commit(`${this.m}setFieldValue`, {
|
||||
field,
|
||||
value: this.mergedInitial.hasOwnProperty(field) ? this.mergedInitial[field] : undefined,
|
||||
form: this.name
|
||||
})
|
||||
}
|
||||
},
|
||||
deregisterField (field) {
|
||||
async deregisterField (field) {
|
||||
await this.whenFinishedValidating
|
||||
this.$store.commit(`${this.m}removeField`, {
|
||||
form: this.name,
|
||||
field
|
||||
@ -151,16 +155,19 @@ export default {
|
||||
label
|
||||
}, validation, this.values)
|
||||
if (!equals(errors || [], (this.validationErrors[field] || []))) {
|
||||
this.updateFieldValidationErrors({field, errors: errors || []})
|
||||
if (this.fields.find(f => f.name === field)) {
|
||||
this.updateFieldValidationErrors({field, errors: errors || []})
|
||||
}
|
||||
}
|
||||
return errors
|
||||
},
|
||||
updateFormValidation () {
|
||||
this.fields.map(async field => this.validateField({
|
||||
async updateFormValidation () {
|
||||
await this.whenFinishedValidating
|
||||
this.whenFinishedValidating = Promise.all(this.fields.map(async field => this.validateField({
|
||||
field: field.name,
|
||||
validation: field.validation,
|
||||
label: field.validationLabel || field.label || field.name
|
||||
}))
|
||||
})))
|
||||
},
|
||||
submit () {
|
||||
if ((this.prevent === 'validation' && this.hasValidationErrors) || (this.prevent === 'any' && this.hasErrors)) {
|
||||
|
@ -90,6 +90,11 @@ export const formulateMutations = (mutations = {}) => Object.assign({
|
||||
state[group][form] = filter(state[group][form], (key, value) => key !== field)
|
||||
}
|
||||
}
|
||||
},
|
||||
removeFieldValidationErrors (state, {form, field}) {
|
||||
state.validationErrors = Object.assign({}, state.validationErrors, {
|
||||
[form]: filter(state.validationErrors[form] || {}, key => key !== field)
|
||||
})
|
||||
}
|
||||
}, mutations)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user