-
-
Notifications
You must be signed in to change notification settings - Fork 43
Fixing form-reset issue #304 #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is the first attempt to fix #304.
@@ -126,8 +126,11 @@ const componentDef = { | |||
self.$store.dispatch('navigateTo', {url: path, backwards: false}) | |||
return; | |||
} | |||
self.setProps(self.data, null); | |||
self.initValues() | |||
if (self.componentConfig["method"] == "post") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fiedl this approach is too implicit in my opinion. I think we cannot rely on the correct usage of http methods. A user might want the form not to reset the form even if using the "post" method. (we never know). We need a explicit option for that:
I recommend something like that:
def form_config
{
for: @test_model,
method: :whatever,
path: "/test_models/#{@test_model.id}",
success: { emit: "update_successful", reset: false }, # reset == true by default (current behavior)
failure: { emit: "form_has_errors" } # reset == false by default (current behavior)
}
end
If you agree on this, please adjust implementation and specs and add the docs (they are missing anyways ;) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree that the behaviour should be configurable. However, I would like to find a default where the form is not reset for an update action which does not redirect to another page, i.e. shows the same form. Otherwise, when the user clicks "save", the form will be reset the the initial form values (before the changes), which probably would feel like a bug.
I will implement the configuration option as you suggested and give the defaults some further thought before suggesting a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the documentation: I've noticed that the "Parameters" section on https://www.matestack.org/docs/components/form.md is empty, yet. Would you like me to add another example to this page showing the new configuration option, or would you like me to start filling the "Parameters" section with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fiedl sorry for the late response. please add the parameter section and add an example for the reset option :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the docs are missing ;) (see discussion above)
Fixing Issue #304: Reset forms only on post requests
Changes