From e814edf9fc4fe498bd49b8271c9023e58cd94bf3 Mon Sep 17 00:00:00 2001 From: Zaytsev Kirill Date: Sun, 25 Oct 2020 22:45:58 +0300 Subject: [PATCH] refactor!: performValidation method renamed to runValidation --- src/FormularioForm.vue | 3 +-- src/FormularioInput.vue | 28 +++++++++++++--------------- test/unit/FormularioForm.test.js | 4 ++-- test/unit/FormularioInput.test.js | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/FormularioForm.vue b/src/FormularioForm.vue index 6f16364..c61fe46 100644 --- a/src/FormularioForm.vue +++ b/src/FormularioForm.vue @@ -195,13 +195,12 @@ export default class FormularioForm extends Vue { hasValidationErrors (): Promise { return Promise.all(this.registry.reduce((resolvers: Promise[], input: FormularioInput) => { - resolvers.push(input.performValidation() && input.hasValidationErrors()) + resolvers.push(input.runValidation() && input.hasValidationErrors()) return resolvers }, [])).then(results => results.some(hasErrors => hasErrors)) } setErrors ({ formErrors, inputErrors }: { formErrors?: string[]; inputErrors?: Record }): void { - // given an object of errors, apply them to this form this.localFormErrors = formErrors || [] this.localFieldErrors = inputErrors || {} } diff --git a/src/FormularioInput.vue b/src/FormularioInput.vue index 6d2533e..6538261 100644 --- a/src/FormularioInput.vue +++ b/src/FormularioInput.vue @@ -89,7 +89,7 @@ export default class FormularioInput extends Vue { get context (): Record { return Object.defineProperty({ name: this.fullQualifiedName, - validate: this.performValidation.bind(this), + runValidation: this.runValidation.bind(this), violations: this.violations, errors: this.mergedErrors, // @TODO: Deprecated, will be removed in next versions, use context.violations & context.errors separately @@ -141,7 +141,7 @@ export default class FormularioInput extends Vue { this.context.model = newValue } if (this.errorBehavior === VALIDATION_BEHAVIOR.LIVE) { - this.performValidation() + this.runValidation() } else { this.violations = [] } @@ -163,7 +163,7 @@ export default class FormularioInput extends Vue { this.addErrorObserver({ callback: this.setErrors, type: 'input', field: this.fullQualifiedName }) } if (this.errorBehavior === VALIDATION_BEHAVIOR.LIVE) { - this.performValidation() + this.runValidation() } } @@ -189,7 +189,7 @@ export default class FormularioInput extends Vue { } } - performValidation (): Promise { + runValidation (): Promise { this.pendingValidation = this.validate().then(violations => { const validationChanged = !shallowEqualObjects(violations, this.violations) this.violations = violations @@ -210,17 +210,15 @@ export default class FormularioInput extends Vue { } validate (): Promise { - return validate( - processConstraints( - this.validation, - this.$formulario.getRules(this.normalizedValidationRules), - this.$formulario.getMessages(this, this.normalizedValidationMessages), - ), { - value: this.context.model, - name: this.context.name, - formValues: this.getFormValues(), - } - ) + return validate(processConstraints( + this.validation, + this.$formulario.getRules(this.normalizedValidationRules), + this.$formulario.getMessages(this, this.normalizedValidationMessages), + ), { + value: this.context.model, + name: this.context.name, + formValues: this.getFormValues(), + }) } hasValidationErrors (): Promise { diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index 9fa272b..1832e99 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -298,7 +298,7 @@ describe('FormularioForm', () => { slots: { default: ` - + `, @@ -321,7 +321,7 @@ describe('FormularioForm', () => { const wrapper = mount(FormularioForm, { slots: { default: ` - + ` } diff --git a/test/unit/FormularioInput.test.js b/test/unit/FormularioInput.test.js index 4df4b5c..620bc10 100644 --- a/test/unit/FormularioInput.test.js +++ b/test/unit/FormularioInput.test.js @@ -245,7 +245,7 @@ describe('FormularioInput', () => { scopedSlots: { default: `
- + {{ error.message }}
`