Skip to content

Commit 438b95b

Browse files
committed
feat(vfg): re-add validateModelField()
1 parent eb33e4b commit 438b95b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/formGenerator.vue

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ export default {
130130
if (newModel != null) {
131131
this.$nextTick(() => {
132132
// Model changed!
133-
if (this.options.validateAfterLoad === true && this.isNewModel !== true) {
134-
this.validate()
133+
if (this.options.validateAfterLoad && this.isNewModel !== true) {
134+
if (Array.isArray(this.options.validateAfterLoad)) {
135+
this.validateModelField(this.options.validateAfterLoad)
136+
} else {
137+
this.validate()
138+
}
135139
} else {
136140
this.clearValidationErrors()
137141
}
@@ -187,6 +191,31 @@ export default {
187191
this.$emit('modelUpdated', newVal, schema)
188192
},
189193
194+
/** Validate one or more model properties */
195+
validateModelField (model) {
196+
/** Determine if the child can and should be validated. */
197+
const toValidate = (child) => isFunction(child.validate) && model.includes(child.field.model)
198+
199+
this.$refs.children.forEach(child => {
200+
if (toValidate(child)) {
201+
child.validate().then((errors) => {
202+
if (errors[0]) {
203+
Object.keys(this.errors)
204+
.filter((key) => {
205+
return this.errors[key].field.model === child.field.model
206+
})
207+
.forEach(key => delete this.errors[key])
208+
209+
this.errors.push({
210+
field: child.field,
211+
error: error[0]
212+
})
213+
}
214+
}).bind(this)
215+
}
216+
})
217+
},
218+
190219
// Validating the model properties
191220
validate(isAsync = null) {
192221
if (isAsync === null) {

0 commit comments

Comments
 (0)