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> {
|
hasValidationErrors (): Promise<boolean> {
|
||||||
return Promise.all(this.registry.reduce((resolvers: Promise<boolean>[], input: FormularioInput) => {
|
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
|
return resolvers
|
||||||
}, [])).then(results => results.some(hasErrors => hasErrors))
|
}, [])).then(results => results.some(hasErrors => hasErrors))
|
||||||
}
|
}
|
||||||
|
|
||||||
setErrors ({ formErrors, inputErrors }: { formErrors?: string[]; inputErrors?: Record<string, string[]> }): void {
|
setErrors ({ formErrors, inputErrors }: { formErrors?: string[]; inputErrors?: Record<string, string[]> }): void {
|
||||||
// given an object of errors, apply them to this form
|
|
||||||
this.localFormErrors = formErrors || []
|
this.localFormErrors = formErrors || []
|
||||||
this.localFieldErrors = inputErrors || {}
|
this.localFieldErrors = inputErrors || {}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ export default class FormularioInput extends Vue {
|
|||||||
get context (): Record<string, any> {
|
get context (): Record<string, any> {
|
||||||
return Object.defineProperty({
|
return Object.defineProperty({
|
||||||
name: this.fullQualifiedName,
|
name: this.fullQualifiedName,
|
||||||
validate: this.performValidation.bind(this),
|
runValidation: this.runValidation.bind(this),
|
||||||
violations: this.violations,
|
violations: this.violations,
|
||||||
errors: this.mergedErrors,
|
errors: this.mergedErrors,
|
||||||
// @TODO: Deprecated, will be removed in next versions, use context.violations & context.errors separately
|
// @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
|
this.context.model = newValue
|
||||||
}
|
}
|
||||||
if (this.errorBehavior === VALIDATION_BEHAVIOR.LIVE) {
|
if (this.errorBehavior === VALIDATION_BEHAVIOR.LIVE) {
|
||||||
this.performValidation()
|
this.runValidation()
|
||||||
} else {
|
} else {
|
||||||
this.violations = []
|
this.violations = []
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ export default class FormularioInput extends Vue {
|
|||||||
this.addErrorObserver({ callback: this.setErrors, type: 'input', field: this.fullQualifiedName })
|
this.addErrorObserver({ callback: this.setErrors, type: 'input', field: this.fullQualifiedName })
|
||||||
}
|
}
|
||||||
if (this.errorBehavior === VALIDATION_BEHAVIOR.LIVE) {
|
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 => {
|
this.pendingValidation = this.validate().then(violations => {
|
||||||
const validationChanged = !shallowEqualObjects(violations, this.violations)
|
const validationChanged = !shallowEqualObjects(violations, this.violations)
|
||||||
this.violations = violations
|
this.violations = violations
|
||||||
@ -210,8 +210,7 @@ export default class FormularioInput extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate (): Promise<Violation[]> {
|
validate (): Promise<Violation[]> {
|
||||||
return validate(
|
return validate(processConstraints(
|
||||||
processConstraints(
|
|
||||||
this.validation,
|
this.validation,
|
||||||
this.$formulario.getRules(this.normalizedValidationRules),
|
this.$formulario.getRules(this.normalizedValidationRules),
|
||||||
this.$formulario.getMessages(this, this.normalizedValidationMessages),
|
this.$formulario.getMessages(this, this.normalizedValidationMessages),
|
||||||
@ -219,8 +218,7 @@ export default class FormularioInput extends Vue {
|
|||||||
value: this.context.model,
|
value: this.context.model,
|
||||||
name: this.context.name,
|
name: this.context.name,
|
||||||
formValues: this.getFormValues(),
|
formValues: this.getFormValues(),
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hasValidationErrors (): Promise<boolean> {
|
hasValidationErrors (): Promise<boolean> {
|
||||||
|
@ -298,7 +298,7 @@ describe('FormularioForm', () => {
|
|||||||
slots: {
|
slots: {
|
||||||
default: `
|
default: `
|
||||||
<FormularioInput v-slot="{ context }" name="foo" validation="required|in:foo">
|
<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>
|
||||||
<FormularioInput name="bar" validation="required" />
|
<FormularioInput name="bar" validation="required" />
|
||||||
`,
|
`,
|
||||||
@ -321,7 +321,7 @@ describe('FormularioForm', () => {
|
|||||||
const wrapper = mount(FormularioForm, {
|
const wrapper = mount(FormularioForm, {
|
||||||
slots: { default: `
|
slots: { default: `
|
||||||
<FormularioInput v-slot="{ context }" name="foo" validation="required|in:foo">
|
<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>
|
||||||
<FormularioInput name="bar" validation="required" />
|
<FormularioInput name="bar" validation="required" />
|
||||||
` }
|
` }
|
||||||
|
@ -245,7 +245,7 @@ describe('FormularioInput', () => {
|
|||||||
scopedSlots: {
|
scopedSlots: {
|
||||||
default: `
|
default: `
|
||||||
<div>
|
<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>
|
<span v-if="props.context.formShouldShowErrors" v-for="error in props.context.allErrors">{{ error.message }}</span>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user