diff --git a/src/FormularioField.vue b/src/FormularioField.vue index 1ed6977..586a1b1 100644 --- a/src/FormularioField.vue +++ b/src/FormularioField.vue @@ -88,8 +88,7 @@ export default class FormularioField extends Vue { } public get model (): unknown { - const model = this.hasModel ? 'value' : 'proxy' - return this.modelGetConverter(this[model]) + return this.modelGetConverter(this.hasModel ? this.value : this.proxy) } public set model (value: unknown) { @@ -185,16 +184,12 @@ export default class FormularioField extends Vue { public runValidation (): Promise { this.validationRun = this.validate().then(violations => { - const validationChanged = !shallowEquals(violations, this.violations) - this.violations = violations - - if (validationChanged) { - this.emitValidation({ - name: this.fullPath, - violations: this.violations, - }) + if (!shallowEquals(this.violations, violations)) { + this.emitValidation(this.fullPath, violations) } + this.violations = violations + return this.violations }) @@ -213,10 +208,10 @@ export default class FormularioField extends Vue { }) } - private emitValidation (payload: { name: string; violations: Violation[] }): void { - this.$emit('validation', payload) + private emitValidation (path: string, violations: Violation[]): void { + this.$emit('validation', { path, violations }) if (typeof this.__FormularioForm_emitValidation === 'function') { - this.__FormularioForm_emitValidation(payload) + this.__FormularioForm_emitValidation(path, violations) } } diff --git a/src/FormularioForm.vue b/src/FormularioForm.vue index 05bc0dc..92a8018 100644 --- a/src/FormularioForm.vue +++ b/src/FormularioForm.vue @@ -136,8 +136,8 @@ export default class FormularioForm extends Vue { } @Provide('__FormularioForm_emitValidation') - private emitValidation (payload: ValidationEventPayload): void { - this.$emit('validation', payload) + private emitValidation (path: string, violations: Violation[]): void { + this.$emit('validation', { path, violations }) } @Watch('state', { deep: true }) diff --git a/test/unit/FormularioField.test.js b/test/unit/FormularioField.test.js index e02980a..73d753a 100644 --- a/test/unit/FormularioField.test.js +++ b/test/unit/FormularioField.test.js @@ -129,7 +129,7 @@ describe('FormularioField', () => { await flushPromises() expect(wrapper.emitted('validation')).toEqual([[{ - name: 'field', + path: 'field', violations: [{ rule: 'required', args: expect.any(Array), diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index 07035d3..a0fe17f 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -371,7 +371,7 @@ describe('FormularioForm', () => { expect(wrapper.emitted('validation')).toBeTruthy() expect(wrapper.emitted('validation')).toEqual([[{ - name: 'foo', + path: 'foo', violations: [], }]]) }) @@ -386,7 +386,7 @@ describe('FormularioForm', () => { expect(wrapper.emitted('validation')).toBeTruthy() expect(wrapper.emitted('validation')).toEqual([[ { - name: 'foo', + path: 'foo', violations: [ { rule: expect.any(String), args: ['foo'],