1
0
mirror of synced 2024-11-22 13:26:06 +03:00

fix: Fixed input event on data with nested objects

This commit is contained in:
1on 2020-10-20 18:40:25 +03:00
parent 06c79905a8
commit ebbf10043b

View File

@ -211,7 +211,7 @@ export default class FormularioForm extends Vue {
} }
} }
setFieldValue (field, value): void { setFieldValue (field, value, emit: boolean = true): void {
if (value === undefined) { if (value === undefined) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [field]: value, ...proxy } = this.proxy const { [field]: value, ...proxy } = this.proxy
@ -219,8 +219,10 @@ export default class FormularioForm extends Vue {
} else { } else {
setNested(this.proxy, field, value) setNested(this.proxy, field, value)
} }
if (emit) {
this.$emit('input', Object.assign({}, this.proxy)) this.$emit('input', Object.assign({}, this.proxy))
} }
}
hasValidationErrors (): Promise<boolean> { hasValidationErrors (): Promise<boolean> {
return Promise.all(this.registry.reduce((resolvers, cmp) => { return Promise.all(this.registry.reduce((resolvers, cmp) => {
@ -247,6 +249,7 @@ export default class FormularioForm extends Vue {
setValues (values: Record<string, any>): void { setValues (values: Record<string, any>): void {
// Collect all keys, existing and incoming // Collect all keys, existing and incoming
const keys = Array.from(new Set(Object.keys(values).concat(Object.keys(this.proxy)))) const keys = Array.from(new Set(Object.keys(values).concat(Object.keys(this.proxy))))
let proxyHasChanges = false;
keys.forEach(field => { keys.forEach(field => {
if (this.registry.hasNested(field)) { if (this.registry.hasNested(field)) {
this.registry.getNested(field).forEach((registryField, registryKey) => { this.registry.getNested(field).forEach((registryField, registryKey) => {
@ -256,7 +259,8 @@ export default class FormularioForm extends Vue {
getNested(this.proxy, registryKey) getNested(this.proxy, registryKey)
) )
) { ) {
this.setFieldValue(registryKey, getNested(values, registryKey)) this.setFieldValue(registryKey, getNested(values, registryKey), false)
proxyHasChanges = true;
} }
if ( if (
@ -271,6 +275,10 @@ export default class FormularioForm extends Vue {
} }
}) })
this.applyInitialValues() this.applyInitialValues()
if (proxyHasChanges) {
this.$emit('input', Object.assign({}, this.proxy))
}
} }
} }
</script> </script>