Git Product home page Git Product logo

Comments (6)

jpdemagalhaes avatar jpdemagalhaes commented on May 13, 2024 4

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.

diego3g avatar diego3g commented on May 13, 2024 4

@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.

diego3g avatar diego3g commented on May 13, 2024 2

@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.

jpdemagalhaes avatar jpdemagalhaes commented on May 13, 2024 1

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.

italoiz avatar italoiz commented on May 13, 2024 1

I was making an implementation to reset the data after sending, passing a reset property that could be three types of values, they are:

  1. string on-success. Only when the submission was successful.
  2. string on-error. Only when an error occurs on the form.
  3. 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.

diego3g avatar diego3g commented on May 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.