Validation is not triggered? #1304
-
Hi Team, This is code I have written to check if the field is empty or not.
But the validation is not getting triggered after clicking on submit button. Questions:
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi. That is because your validator does not have the correct condition const validatorMapper = {
required: () => (value) => (value === "" ? "Field is required" : undefined)
}; The initial value in the form is not an empty string // default value
const validatorMapper = {
required: () => (value = "") =>
value === "" ? "Field is required" : undefined
};
//const validatorMapper = {
required: () => (value) => !value ? "Field is required" : undefined
}; BTW in order to have a custom require validator to cover all possible value types. You will need a bit more complex condition. I would suggest the default one as I believe it covers all edge cases. If you just want to change the error message, you can customize the default validator like this: https://data-driven-forms.org/schema/custom-validator-message |
Beta Was this translation helpful? Give feedback.
@Nilesh9768
Hi. That is because your validator does not have the correct condition
The initial value in the form is not an empty string
""
but isundefined
. So yourvalue === ""
is false. You can fix it by simply adding a default value to the argument or removing the comparison. OR I am sure there is a lot of other ways. Here are some examplesBTW in orde…