Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

Option list unwanted memory autosave form #1721

Open polygonwood opened 2 years ago

polygonwood commented 2 years ago

Describe the bug

Using a (small) autoform , type normal with autosave=true and on-submit hook to perform action, consisting of only one input field with options, there is a 'memory' effect of last selected option. E.g. select a value (which in my case restricts a query), move away from that route (iron router), come back to the route, it looks like re-freshed but when you click the same option you selected before, the submit hook is not executed. Selecting another value triggers the submit hook again

A clear and concise description of what the bug is.

To Reproduce

I have created a replicator : live on galaxy source code on github

click on route 1, select e.g. option 1 from drop down selector, go back to top and click again on route 1 and select the same option, you will see no response below (or in console), selecting another option does trigger the on-submit hook again

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

I expect Autoform.resetForm(formID) to clear the memory of the last selected option. Any selected option after reset should re-trigger the submit hook.

Screenshots

If applicable, add screenshots to help explain your problem. Please avoid screenshots of code or error outputs and use formatted code via markdown instead.

movie at link recording shows the behavior, at around second 10-11 you see the unwanted behaviour (not reacting to selection option 'Bestuur' for the second time ...)

Versions (please complete the following information):

Meteor 2.7.3 Autoform 7.0.0 Browser Chrome 103

Additional context

Add any other context about the problem here.

jankapunkt commented 2 years ago

Thank you @polygonwood I will take a look at it. I already found resetForm not to be working properly.

polygonwood commented 2 years ago

Jan thanks,

I have created a replicator : live on galaxy https://selectorrepro.eu.meteorapp.com/ source code on github https://github.com/polygonwood/selectorrepro

click on route 1, select e.g. option 1 from drop down selector, go back to top and click again on route 1 and select the same option, you will see no response below (or in console), selecting another option does trigger the on-submit hook again

regards Ronny

On Fri, Jul 29, 2022 at 2:15 AM Jan Küster @.***> wrote:

Thank you @polygonwood https://github.com/polygonwood I will take a look at it. I already found resetForm not to be working properly.

— Reply to this email directly, view it on GitHub https://github.com/Meteor-Community-Packages/meteor-autoform/issues/1721#issuecomment-1198743507, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMTJC25L3DJ7XAR6MUW2A73VWMPD3ANCNFSM546EM7PQ . You are receiving this because you were mentioned.Message ID: @.*** com>

polygonwood commented 1 year ago

Jan This has to do with the module variable lastKeyVals in autoform-events.js Once an autosave event has occurred, the last value of the last changed field is kept in the lastKeyVals object, even after submit, reserForm, ... I have solved it for my application by adding a clearLastKeyVal() function to the hookContext, allowing me to clear that memory e.g. in a onSubmit hook (so that next usage of the form doesn't suffer from that). This could perhaps also be added to the resetForm in general ? I'm not generating a pull request because I'm not to deeply knowledgable to understand what the preferred option is to avoid this situation.

jankapunkt commented 1 year ago

possible to be fixed via #1602