reset individual input state #6884
Replies: 6 comments 17 replies
-
I got one more proposal which could possibly alow to reset multiple fields by one row instead of using for loop:
Otherwise I vote for B as it provides also a way to set state of input. |
Beta Was this translation helpful? Give feedback.
-
Hello. I would like to take this moment to thank for the cool library. ^^` I think it would be great if you could resetting a specific field directly to the But I read the @bluebill1049's answer for @mysuf, so I join him and vote for option B. |
Beta Was this translation helpful? Give feedback.
-
I wonder if it's cleaner to keep some of it separate in option B // Option B revised
resetField(‘name’); // reset field value to default value and state
resetField(‘name’, { keepError: false, keepTouch: false, keepDirty: false }) // keep some of the filed state
setDefault(‘name’, ‘newValue’); // change default field value RANT: (feel free to disregard)
This essentially means you have two separate Maybe it's better try try and make a setField(‘name‘, ‘newValue‘, { validate: true, dirty: true })
// sets field value and makes it validate and sets it as dirty
setField(‘name‘, { error: { type: "error", message: "Ups!"}, touch: false, dirty: false })
// losses the touch(ed) and dirty value, but sets a new error,
// alternatively could also receive a boolean, to specify
// if it should loose, or keep the current error.
setField(‘name‘, { resetValue: true, error: false, touch: false, dirty: false }) // Resets all state and the specifically the value
// -------
setField(‘name‘, ‘newValue‘, { reset: true, updateDefaultValue: true })
OR
setField(‘name‘, { reset: true })
setDefault(‘name’, ‘newValue’); // change default field value
// Resets the field, updates the default, but also gets dirty
setField(‘name‘, ‘newValue‘, { reset: true, updateDefaultValue: true, dirty: true }) |
Beta Was this translation helpful? Give feedback.
-
I prefer option B it seems closer to the current react hook form API. Here's my question, what happens if the |
Beta Was this translation helpful? Give feedback.
-
Personally I like resetField (option B), but to be clear, is this supported? resetField(‘name’, 'value', { keepError: false, keepTouch: false, keepDirty: false }) // reset state w/ options but with new default value If you did put it the object (as mentioned in the thread with @getTobiasNielsen), maybe make it clear what the value is: resetField('name', {
newDefaultValue: '...'
keepDirty: true,
keepValue: true,
keepDefaultValues: true
}) |
Beta Was this translation helpful? Give feedback.
-
Option B. I'd rather have more functions that are focused and simple rather than a few functions that are complex and can be used for many cases. Using |
Beta Was this translation helpful? Give feedback.
-
Context
The current status of using
reset
API can be quite complex when it comes to resetting an individual input state. We would like to expose a new API or config to combat this problem, so developer experience can be enhanced. At the moment, we have two API purposes in the planning and would like to get the community's thoughts over which.Props
reset
the entire formCons
Proposal
Here are the two options which we are considering:
Option AOption BOption A: leverage existing API, no need to remember another, the only concern is the setting value toundefined
it's not that intuitive.Option B: new API more flexible and more declarative and self-explanatory, however increasing the amount of the API for the lib.Sytnax
The following is the good outcome with a new API focused on resetting input state/value.
PR (draft)
#6891
cc @barrymay @kotarella1110 @jorisre @wdfinch @getTobiasNielsen
Beta Was this translation helpful? Give feedback.
All reactions