Skip to content

Validation is not triggered? #1304

Discussion options

You must be logged in to vote

@Nilesh9768

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 "" but is undefined. So your value === "" 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 examples

// default value
const validatorMapper = {
  required: () => (value = "") =>
    value === "" ? "Field is required" : undefined
};

//const validatorMapper = {
  required: () => (value) => !value ? "Field is required" : undefined
};

BTW in orde…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Hyperkid123
Comment options

@rvsia
Comment options

@Nilesh9768
Comment options

@Hyperkid123
Comment options

@Nilesh9768
Comment options

Answer selected by Nilesh9768
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants