feat!: Validation event payload property "name" renamed to "path"
This commit is contained in:
parent
a1476d9986
commit
7c2a9e8110
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 })
|
||||||
|
@ -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),
|
||||||
|
@ -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'],
|
||||||
|
Loading…
Reference in New Issue
Block a user