Do we need an API to define that the onChange validator is launched also on mount? #1005
Replies: 3 comments 4 replies
-
I think so. I'm having to do this right now (little cludgy workaround using radashi's objectify, but obviously another helper could be written): validators={objectify(['onMount', 'onBlur'], identity, () =>
v.pipe(v.number(), v.minValue(1), v.maxValue(999))
)} I don't think it's particularly ideal. |
Beta Was this translation helpful? Give feedback.
-
We definitely need an api for this! :) We are running quite complex forms with plenty of fields (thus everything is quite typescript heavy). It would be perhaps best to have a flag that is onAny: () => {} and/or directly passing a function into validators={} that does that job. |
Beta Was this translation helpful? Give feedback.
-
I also want to point out that using two validators this way results in duplicate error messages for empty required fields where the user has clicked into an input and clicked away without entering a value. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In some cases we might want our form to run the onChange validator as soon as the component mounts, do we need a specific API to handle that?
After #726 (version 0.34.4) you can easily achieve that by defining your validating function and passing it to both validators
This will set
canSubmit
to false if there are errors but will not setisTouched
to fields so the user can control if they want to show the error or not.(See Stackblitz with zod)
Is that enough or we need something at Form/Field level to declare that? Suggestions and ideas are welcome!
Beta Was this translation helpful? Give feedback.
All reactions