1
0
mirror of synced 2024-11-22 05:16:05 +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 {
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<Violation[]> {
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)
}
}

View File

@ -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 })

View File

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

View File

@ -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'],