reactjsreact-final-form

React-final-form ignores Field validate property change


On click on a checkbox, I'm changing the "validate" property of another field. The problem is the following: "validate" field is changed and I can see it in React inspector, but react-final-form calls an old validator.

You can see a demo here: https://codesandbox.io/embed/nny0zxz4rm If you click on the checkbox and then Submit - form will be submitted and validator ignored. If you click the checkbox twice - nonrequired field will prevent form submit.

I can't change the validator's code and can't see any other options to fix this issue.


Solution

  • This does look like a bug. The field-level validation was not designed with the idea of swapping validation functions so quickly like this. However, until this is fixed, there is a way to accomplish this. https://codesandbox.io/s/pyr69znvnq