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

feat!: Validation event payload property "name" renamed to "path"

This commit is contained in:
Zaytsev Kirill 2021-06-11 22:43:30 +03:00
parent a1476d9986
commit 7c2a9e8110
4 changed files with 13 additions and 18 deletions

View File

@ -88,8 +88,7 @@ export default class FormularioField extends Vue {
} }
public get model (): unknown { public get model (): unknown {
const model = this.hasModel ? 'value' : 'proxy' return this.modelGetConverter(this.hasModel ? this.value : this.proxy)
return this.modelGetConverter(this[model])
} }
public set model (value: unknown) { public set model (value: unknown) {
@ -185,16 +184,12 @@ export default class FormularioField extends Vue {
public runValidation (): Promise<Violation[]> { public runValidation (): Promise<Violation[]> {
this.validationRun = this.validate().then(violations => { this.validationRun = this.validate().then(violations => {
const validationChanged = !shallowEquals(violations, this.violations) if (!shallowEquals(this.violations, violations)) {
this.violations = violations this.emitValidation(this.fullPath, violations)
if (validationChanged) {
this.emitValidation({
name: this.fullPath,
violations: this.violations,
})
} }
this.violations = violations
return this.violations return this.violations
}) })
@ -213,10 +208,10 @@ export default class FormularioField extends Vue {
}) })
} }
private emitValidation (payload: { name: string; violations: Violation[] }): void { private emitValidation (path: string, violations: Violation[]): void {
this.$emit('validation', payload) this.$emit('validation', { path, violations })
if (typeof this.__FormularioForm_emitValidation === 'function') { if (typeof this.__FormularioForm_emitValidation === 'function') {
this.__FormularioForm_emitValidation(payload) this.__FormularioForm_emitValidation(path, violations)
} }
} }

View File

@ -136,8 +136,8 @@ export default class FormularioForm extends Vue {
} }
@Provide('__FormularioForm_emitValidation') @Provide('__FormularioForm_emitValidation')
private emitValidation (payload: ValidationEventPayload): void { private emitValidation (path: string, violations: Violation[]): void {
this.$emit('validation', payload) this.$emit('validation', { path, violations })
} }
@Watch('state', { deep: true }) @Watch('state', { deep: true })

View File

@ -129,7 +129,7 @@ describe('FormularioField', () => {
await flushPromises() await flushPromises()
expect(wrapper.emitted('validation')).toEqual([[{ expect(wrapper.emitted('validation')).toEqual([[{
name: 'field', path: 'field',
violations: [{ violations: [{
rule: 'required', rule: 'required',
args: expect.any(Array), args: expect.any(Array),

View File

@ -371,7 +371,7 @@ describe('FormularioForm', () => {
expect(wrapper.emitted('validation')).toBeTruthy() expect(wrapper.emitted('validation')).toBeTruthy()
expect(wrapper.emitted('validation')).toEqual([[{ expect(wrapper.emitted('validation')).toEqual([[{
name: 'foo', path: 'foo',
violations: [], violations: [],
}]]) }]])
}) })
@ -386,7 +386,7 @@ describe('FormularioForm', () => {
expect(wrapper.emitted('validation')).toBeTruthy() expect(wrapper.emitted('validation')).toBeTruthy()
expect(wrapper.emitted('validation')).toEqual([[ { expect(wrapper.emitted('validation')).toEqual([[ {
name: 'foo', path: 'foo',
violations: [ { violations: [ {
rule: expect.any(String), rule: expect.any(String),
args: ['foo'], args: ['foo'],