A package for adding validation to my account.
import initializeYupSchema, { OverrideYupSchemaType, ValidationFieldNames, } from '@newskit-render/validation'
import \* as yup from 'yup'
/_ Example of name validation override _/
const nameValidation = yup.object().shape({
firstName: yup.string().required('First Name is required overriden'),
lastName: yup.string().required('Last Name is required overriden'),
})
/_ Example of required fields override _/
const requiredFieldsOverride = [
ValidationFieldNames.firstName,
ValidationFieldNames.line1,
ValidationFieldNames.mobile,
]
/_ Pass your override schema to here, so it's delegated accordingly _/
const overrideYupSchema: OverrideYupSchemaType = {
name: nameValidation,
options: {
overrideRequiredFields: requiredFieldsOverride
}
}
export default initializeYupSchema({overrideYupSchema})
You can pass message templates, that will be used as the template of the required messages and wrong format messages.
export default initializeYupSchema({
overrideYupSchema: overrideYupSchema,
options: {
requiredMessage: "Please enter your ${field}",
wrongFormatMessage : '${field} is wrong format'
}
})