Skip to content

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

Merged
merged 8 commits into from
Feb 10, 2020

Conversation

fiedl
Copy link
Collaborator

@fiedl fiedl commented Dec 15, 2019

Fixing Issue #304: Reset forms only on post requests

Changes

  • On form submit, reset input fields to their init values only on push requests, not on put requests.
  • Add spec for a typical scenario, where a form is used to update a model. After submitting the form, no transition is used, only a message is shown. This means that the form stays visible, which is the reason for not resetting the values. (Otherwise, the form would be reset to the old values.)

@fiedl fiedl requested a review from jonasjabari December 15, 2019 22:38
@@ -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")
Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Member

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

Copy link
Member

@jonasjabari jonasjabari left a 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)

@jonasjabari jonasjabari merged commit 2337d87 into develop Feb 10, 2020
@jonasjabari jonasjabari added this to the 0.7.4 milestone Feb 10, 2020
@pascalwengerter pascalwengerter deleted the sf/fix-form-reset-on-update-issue-304 branch February 17, 2020 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants