From ebbf10043b2951dc5769239dade6a001a38cde0a Mon Sep 17 00:00:00 2001 From: 1on Date: Tue, 20 Oct 2020 18:40:25 +0300 Subject: [PATCH] fix: Fixed input event on data with nested objects --- src/FormularioForm.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/FormularioForm.vue b/src/FormularioForm.vue index f4b2ad6..d8bfc87 100644 --- a/src/FormularioForm.vue +++ b/src/FormularioForm.vue @@ -211,7 +211,7 @@ export default class FormularioForm extends Vue { } } - setFieldValue (field, value): void { + setFieldValue (field, value, emit: boolean = true): void { if (value === undefined) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { [field]: value, ...proxy } = this.proxy @@ -219,7 +219,9 @@ export default class FormularioForm extends Vue { } else { setNested(this.proxy, field, value) } - this.$emit('input', Object.assign({}, this.proxy)) + if (emit) { + this.$emit('input', Object.assign({}, this.proxy)) + } } hasValidationErrors (): Promise { @@ -247,6 +249,7 @@ export default class FormularioForm extends Vue { setValues (values: Record): void { // Collect all keys, existing and incoming const keys = Array.from(new Set(Object.keys(values).concat(Object.keys(this.proxy)))) + let proxyHasChanges = false; keys.forEach(field => { if (this.registry.hasNested(field)) { this.registry.getNested(field).forEach((registryField, registryKey) => { @@ -256,7 +259,8 @@ export default class FormularioForm extends Vue { getNested(this.proxy, registryKey) ) ) { - this.setFieldValue(registryKey, getNested(values, registryKey)) + this.setFieldValue(registryKey, getNested(values, registryKey), false) + proxyHasChanges = true; } if ( @@ -271,6 +275,10 @@ export default class FormularioForm extends Vue { } }) this.applyInitialValues() + + if (proxyHasChanges) { + this.$emit('input', Object.assign({}, this.proxy)) + } } }