teslamotors / informed

A lightweight framework and utility for building powerful forms in React applications
https://teslamotors.github.io/informed
MIT License
956 stars 173 forks source link

Feature request: making reset controllable #386

Closed behzadmehrabi closed 2 years ago

behzadmehrabi commented 2 years ago

Currently, the reset function on field doesn't take any parameter. I think it would be better to make it more flexible by taking parameters such as the value to be reset into and keeping which states. it can be something like:

function reset(options) {
    ...
}

where options are:

there are so many use cases for it, the reason I personally need this is I want to reset the field to some value and reset everything else. so for me, it would be:

reset({ value: 'elon' })

AFAIK it's not possible to do at the moment.

I can make PR for it.

joepuzzo commented 2 years ago

Took a look at PR. Interesting idea. I added some comments if you could address those. Also need to think about... did I miss resetting pristine and dirty 🤔

joepuzzo commented 2 years ago

https://github.com/teslamotors/informed/blob/master/__tests__/hooks/useFormApi.test.js#L56

Im trying to think about this ? Should this actually be reset 🤔

behzadmehrabi commented 2 years ago

Took a look at PR. Interesting idea. I added some comments if you could address those. Also need to think about... did I miss resetting pristine and dirty 🤔

I wrote about it in the PR comments, I think there is a bug.

joepuzzo commented 2 years ago

@Bezmehrabi merged thanks. I will think more on if the pristine thing is a bug. But for now your code is in!