0
I have a model in which fills the fields of a form (use Asp.net mvc and the view is typed), that is, I load the fields of this form according to the data of the database for the user to change in the editing screen.
What I want to do is a "undo" button that resets to the initial state of the data that came from the database, not simply using this.meuform.reset() at the click of the button.
I believe that it should be done in the form onload() a way to save the current elements of the form and when clicked on the button, simply play again in the elements, these saved elements...
I prefer pure Javascript.
Dude, it’s not clear to me what you want to do. The
reset()
in itself already reset the value for the initial state, that is, return its value to what is in the attributevalue
, that was set initially. Now, did not understand your last paragraph.– DontVoteMeDown
is that the reset it "Zera" all fields, puts "" in all the right values? I want to leave the fields with the values of the model, for example: I search in the bank the name john and fill in the input value with this name, then I change this name again.. after that, I want to click and go back to the amount that came back from the bank that was "João".
– Luiz Negrini
I don’t think so, man
reset
does not clear the values but resets them even to the initial value, take a look at in this example. As far as I know,Html.EditorFor
or similar that you may be using, generates the value in the attributevalue
, which is the correct standard. So the reset was supposed to work.– DontVoteMeDown
It really makes sense, I will test again, I may have made some mistake, warning here then, if solve, can post as response.
– Luiz Negrini
@Dontvotemedown I believe that it is really working, but I would like to take the form without having to set a name or ID for it, because it would have to be set in all the Foms of all pages, is there any way Generic to pick up? ? Document.getelementsbytagname("form"). reset();
– Luiz Negrini
No, this type of writing works in jQuery because it runs a loop internally. The
getElementsByTagName()
returns a collection that has no methodreset()
. You’d have to run the loop yourself, example– DontVoteMeDown
have how to post as answer to both questions? Can be in jquery.
– Luiz Negrini
@Dontvotemedown look at the comment above, if you can, wait. Thanks for the help.
– Luiz Negrini
Whoa, buddy, you got it.
– DontVoteMeDown