Comments (6)
I was thinking something like clearOnSubmit
prop inside <Form>
, but I like yours better.
Should we reset form after submit automatically?
Personally I think that the form should not reset automatically. We should either provide a prop like clearOnSubmit
or a helper like you suggested.
How edit cases would work? Clear data or return to initial data?
Perhaps we should offer the option to pass the data inside reset()
? So if you need to return the state to its initial data you'd do reset(initialData)
, if empty, clears the inputs.
@diego3g could you provide an example of a situation where it might be needed to reset the inputs to its initial data (assuming they're populated, of course).
from unform.
@jpdemagalhaes Great, forgot about that! So let's keep with the helper idea, i think it's more readable and extendable as we are able to send params and have more helpers.
from unform.
@italoiz Great! We are looking into it. I've got the same problem in Jest but i managed to do it, but got some other problems with custom and select element. I got only input and textarea working for now. I'll probably send one PR until the weekend.
from unform.
Hmm, clearing a form with a button is possible with <input type="reset" />
. It creates a button that when pressed clears all the inputs of the form, and when you have defaultValue
, it returns to that state.
Which got me thinking. I feel like the only thing we should provide is clearOnSubmit
prop, or like you suggested, a helper, which would be useful to reset the fields automatically after a submit. What do you think @diego3g ?
from unform.
I was making an implementation to reset the data after sending, passing a reset
property that could be three types of values, they are:
- string
on-success
. Only when the submission was successful. - string
on-error
. Only when an error occurs on the form. - string
on-submit
. In both cases above.
I stopped the feature when I saw this discussion.
My idea was following the logic of @jpdemagalhaes, but I was having trouble testing the call of a parameter that could be passed, the onReset
. For some reason Jest could not identify.
Example:
<Form onReset={handleReset} reset="on-success" ... />
I had thought of a solution similar to that of @diego3g, I did not continue to think it was not so good when the other alternative. But seeing this discourse, realize that it is the best way.
For this reason, I believe that @diego3g solution is good.
from unform.
@jpdemagalhaes Great!
The example would be something like an reset button (is it still used?) inside the form near the submit. But i really think it's something we should not implement.
from unform.
Related Issues (20)
- Expo ImagePicker, DocumentPicker, Typescript example
- more informative error message when `useField` is being used in a component that's not a child of <Form>
- react-native-masked-text undefined field HOT 1
- error in the return oh the typing of the path
- TypeError: a is undefined
- Support middleware in getValue HOT 1
- formRef.current new key referring to form's html element
- The best way to create dynamic arrays with unform HOT 5
- need to add the css property to work correctly HOT 1
- How to get if a form is dirty? HOT 2
- Picker Select React Native
- edit form with setdata HOT 2
- Unform React Select Example Doc HOT 1
- Looking for some way to use unform in a <tr/> HOT 2
- Multiples Checkboxes whitin one form: HOT 1
- Access input value via useEffect
- How to get only data that have value HOT 1
- initialData not working HOT 3
- Persist Data HOT 6
- Radio Input with typecript HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unform.