Form validations
Configuring form field validations
import { field, defineFormPage, FieldType } from '@opencrvs/toolkit/events'
export const father = defineFormPage({
id: 'father',
title: {
defaultMessage: "Father's details",
description: 'Form section title for fathers details',
id: 'form.section.father.title'
},
fields: [
// ... other fields
{
id: 'father.dob',
type: FieldType.DATE,
validation: [
{
message: {
defaultMessage: 'Must be a valid Birthdate',
description: 'This is the error message for invalid date',
id: 'event.birth.action.declare.form.section.person.field.dob.error'
},
validator: field('father.dob').isBefore().now()
},
{
message: {
defaultMessage: "Birth date must be before child's birth date",
description:
"This is the error message for a birth date after child's birth date",
id: 'event.birth.action.declare.form.section.person.dob.afterChild'
},
validator: field('father.dob').isBefore().date(field('child.dob'))
}
]
}
]
})

ValidationConfig schema
Last updated