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 {
|
return {
|
||||||
parentIdentifier: 'vue-formulate-wrapper-element',
|
parentIdentifier: 'vue-formulate-wrapper-element',
|
||||||
forceErrors: null,
|
forceErrors: null,
|
||||||
fieldInitials: {}
|
fieldInitials: {},
|
||||||
|
whenFinishedValidating: Promise.resolve()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -103,13 +104,16 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
registerField (field, data) {
|
registerField (field, data) {
|
||||||
this.$store.commit(`${this.m}setFieldMeta`, {form: this.name, field, data})
|
this.$store.commit(`${this.m}setFieldMeta`, {form: this.name, field, data})
|
||||||
|
if (data.type !== 'submit') {
|
||||||
this.$store.commit(`${this.m}setFieldValue`, {
|
this.$store.commit(`${this.m}setFieldValue`, {
|
||||||
field,
|
field,
|
||||||
value: this.mergedInitial.hasOwnProperty(field) ? this.mergedInitial[field] : undefined,
|
value: this.mergedInitial.hasOwnProperty(field) ? this.mergedInitial[field] : undefined,
|
||||||
form: this.name
|
form: this.name
|
||||||
})
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deregisterField (field) {
|
async deregisterField (field) {
|
||||||
|
await this.whenFinishedValidating
|
||||||
this.$store.commit(`${this.m}removeField`, {
|
this.$store.commit(`${this.m}removeField`, {
|
||||||
form: this.name,
|
form: this.name,
|
||||||
field
|
field
|
||||||
@ -151,16 +155,19 @@ export default {
|
|||||||
label
|
label
|
||||||
}, validation, this.values)
|
}, validation, this.values)
|
||||||
if (!equals(errors || [], (this.validationErrors[field] || []))) {
|
if (!equals(errors || [], (this.validationErrors[field] || []))) {
|
||||||
|
if (this.fields.find(f => f.name === field)) {
|
||||||
this.updateFieldValidationErrors({field, errors: errors || []})
|
this.updateFieldValidationErrors({field, errors: errors || []})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return errors
|
return errors
|
||||||
},
|
},
|
||||||
updateFormValidation () {
|
async updateFormValidation () {
|
||||||
this.fields.map(async field => this.validateField({
|
await this.whenFinishedValidating
|
||||||
|
this.whenFinishedValidating = Promise.all(this.fields.map(async field => this.validateField({
|
||||||
field: field.name,
|
field: field.name,
|
||||||
validation: field.validation,
|
validation: field.validation,
|
||||||
label: field.validationLabel || field.label || field.name
|
label: field.validationLabel || field.label || field.name
|
||||||
}))
|
})))
|
||||||
},
|
},
|
||||||
submit () {
|
submit () {
|
||||||
if ((this.prevent === 'validation' && this.hasValidationErrors) || (this.prevent === 'any' && this.hasErrors)) {
|
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)
|
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)
|
}, mutations)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user