refactor!: performValidation method renamed to runValidation
This commit is contained in:
parent
b1e126a149
commit
e814edf9fc
@ -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 || {}
|
||||
}
|
||||
|
@ -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,8 +210,7 @@ export default class FormularioInput extends Vue {
|
||||
}
|
||||
|
||||
validate (): Promise<Violation[]> {
|
||||
return validate(
|
||||
processConstraints(
|
||||
return validate(processConstraints(
|
||||
this.validation,
|
||||
this.$formulario.getRules(this.normalizedValidationRules),
|
||||
this.$formulario.getMessages(this, this.normalizedValidationMessages),
|
||||
@ -219,8 +218,7 @@ export default class FormularioInput extends Vue {
|
||||
value: this.context.model,
|
||||
name: this.context.name,
|
||||
formValues: this.getFormValues(),
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
hasValidationErrors (): Promise<boolean> {
|
||||
|
@ -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" />
|
||||
` }
|
||||
|
@ -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>
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user