1
0
mirror of synced 2024-11-25 14:56:03 +03:00

refactor!: performValidation method renamed to runValidation

This commit is contained in:
Zaytsev Kirill 2020-10-25 22:45:58 +03:00
parent b1e126a149
commit e814edf9fc
4 changed files with 17 additions and 20 deletions

View File

@ -195,13 +195,12 @@ export default class FormularioForm extends Vue {
hasValidationErrors (): Promise<boolean> {
return Promise.all(this.registry.reduce((resolvers: Promise<boolean>[], 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<string, string[]> }): void {
// given an object of errors, apply them to this form
this.localFormErrors = formErrors || []
this.localFieldErrors = inputErrors || {}
}

View File

@ -89,7 +89,7 @@ export default class FormularioInput extends Vue {
get context (): Record<string, any> {
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<void> {
runValidation (): Promise<void> {
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<Violation[]> {
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<boolean> {

View File

@ -298,7 +298,7 @@ describe('FormularioForm', () => {
slots: {
default: `
<FormularioInput v-slot="{ context }" name="foo" validation="required|in:foo">
<input v-model="context.model" type="text" @blur="context.validate()">
<input v-model="context.model" type="text" @blur="context.runValidation()">
</FormularioInput>
<FormularioInput name="bar" validation="required" />
`,
@ -321,7 +321,7 @@ describe('FormularioForm', () => {
const wrapper = mount(FormularioForm, {
slots: { default: `
<FormularioInput v-slot="{ context }" name="foo" validation="required|in:foo">
<input v-model="context.model" type="text" @blur="context.validate()">
<input v-model="context.model" type="text" @blur="context.runValidation()">
</FormularioInput>
<FormularioInput name="bar" validation="required" />
` }

View File

@ -245,7 +245,7 @@ describe('FormularioInput', () => {
scopedSlots: {
default: `
<div>
<input v-model="props.context.model" @blur="props.context.validate()">
<input v-model="props.context.model" @blur="props.context.runValidation()">
<span v-if="props.context.formShouldShowErrors" v-for="error in props.context.allErrors">{{ error.message }}</span>
</div>
`