remix-validated-form icon indicating copy to clipboard operation
remix-validated-form copied to clipboard

[Feature]: Form `onFormChange` and accompanying hook.

Open zachrip opened this issue 1 year ago • 2 comments

What is the new or updated feature that you are suggesting?

I would like to have an onFormChange handler that is aware of all fields in the form. Currently there is no way to do this if you make use of custom components as they don't emit onChange events.

<ValidatedForm onFormChange={form => {
  // can access the same values as the useFormContext hook
}}>
  ...
</ValidatedForm>

Why should this feature be included?

It makes it possible to do some things that aren't currently possible (ergonomically). In my case I want to submit the form every time it changes.

zachrip avatar Aug 02 '23 13:08 zachrip

This seems reasonable. I think just having a useFormChange hook is probably enough for a first pass. My thinking is we would listen to any regular change event or change to a controlled field and invoke the handler with the entire FormData object. I'm not sure when I'll have time to get around to this, but I'm happy to provide guidance if you want try making a PR for this.

airjp73 avatar Aug 11 '23 16:08 airjp73

I really support this idea, for example I have a 'save' button and it would be reasonable for the button to be disabled if it is the same as the previous saved value. @airjp73 Is there a workaround currently for this?

k11q avatar Aug 29 '23 23:08 k11q

RVF v6 has been released 🎉

This should be possible now using the subscribe api.

You can find the documentation here and the migration guide here.

airjp73 avatar Aug 08 '24 20:08 airjp73