ariakit
ariakit copied to clipboard
`useFormStore` - Return `isTouched()` Prop
Motivation
It would be handy to be able to check if any field in the form has been touched. Currently I believe you can only check individual fields? However I might be missing something.
Usage example
const isTouched = store.isTouched();
Requirements
- The function should return
true
if one or more fields has been touched - The function should return
false
if none of the fields have been touched, or the form has been resetg
Workaround
Define a constant each time you need to check if any of the fields have been touched:
const isTouched = Object.keys( store.useState( 'touched' ) ).length > 0;
Possible implementations
No response
ran into this myself. I was trying to prevent form submission if nothing has been touched but on submission, everything is considered touch. In hindsight this makes sense but just thought I'd add my experience and what I was trying to do