This page explores the configure method used to define global settings for form validation in your SPA application. Effectively configuring these options can streamline your development process.
The configure method accepts a single argument of type FormConfig. This object allows you to set various properties that influence form validation behavior throughout your application. Let's break down the key configuration options:
errorMessage (Optional):dateConfig (Optional):separator (string): Defines the separator used between date components (e.g., "/" for "mm/dd/yyyy").format (string): Specifies the format for displaying dates. Possible values include:
"mdy": Month-Day-Year (e.g., "01/31/2024")
"dmy": Day-Month-Year (e.g., "31/01/2024")
"ymd": Year-Month-Day (e.g., "2024/01/31")runValidatorStrategy (Optional):RunValidatorStrategy.None (default): Runs on every value change.RunValidatorStrategy.OnSubmit: Runs validation only when the form is submitted (e.g., upon clicking a submit button).RunValidatorStrategy.None provides real-time feedback to users as they interact with the form, while RunValidatorStrategy.OnSubmit is suitable for scenarios where validation upon form submission is sufficient.Here's a code snippet demonstrating how to use the configure method with some of the options explained earlier:
import { configure } from "@nattyjs/tidy";
configure({
errorMessage: {
validator:{
required: 'This field is mandatory.'
},
},
dateConfig: {
separator: '-',
format: 'ymd',
},
runValidatorStrategy: RunValidatorStrategy.OnSubmit,
});