ariakit icon indicating copy to clipboard operation
ariakit copied to clipboard

`useFormStore` - Return `isTouched()` Prop

Open spencerfinnell opened this issue 1 year ago • 1 comments

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

spencerfinnell avatar Oct 09 '23 13:10 spencerfinnell

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

petejodo avatar Oct 12 '23 03:10 petejodo