Skip to content
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

🛠️ Fix active form vs form data loading #134

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

germsvel
Copy link
Owner

@germsvel germsvel commented Oct 4, 2024

Resolves #105

What changed?

At some point, a page's default data (parsed in Form) would become part of the ActiveForm form data.

That meant that if the data on the page changed, the stuff that had been filled in on a previous form action would prevail because it was acting as part of the "active form" data.

This is the way this should work (done in this commit):

  • ActiveForm should ONLY keep track of fields that have been filled in. The rest of the data to submit should come from form.form_data. We should not copy it and keep track of it there.

  • click_button, submit, and anything else that triggers changes (like phx-change) should know to combine form.form_data ++ ActiveForm.form_data before sending it to the server.

  • We should probably keep track of form data in a map instead of a list of tuples. We used to keep it in a nested map, and we wanted to flatten it. We should still keep it flat, but we should make it a map. That's left for future work since it's not affecting the current fix.

Test notes

We move common form helper behavior tests out of fill_in and into a shared tests group.

What changed?
=============

At some point, a page's default data (parsed in `Form`) would become
part of the `ActiveForm` form data.

That meant that if the data on the page changed, the stuff that had been
filled in on a previous form action would prevail because it was acting
as part of the "active form" data.

This is the way this should work (done in this commit):

- `ActiveForm` should _ONLY_ keep track of fields that have been filled
  in. The rest of the data to submit should come from `form.form_data`.
  We should not copy it and keep track of it there.

- `click_button`, `submit`, and anything else that triggers changes
  (like `phx-change`) should know to combine `form.form_data ++
  ActiveForm.form_data` before sending it to the server.

- We should probably keep track of form data in a map instead of a list
  of tuples. We used to keep it in a nested map, and we wanted to
  flatten it. We should still keep it flat, but we should make it a map.
  That's left for future work since it's not affecting the current fix.

Test notes
----------

We move common form helper behavior tests out of fill_in and into a
shared tests group.
@germsvel germsvel merged commit 37302b9 into main Oct 4, 2024
3 checks passed
@germsvel germsvel deleted the fix-active-form-tracking branch October 4, 2024 20:01
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.

Error when hidden field is updated by server
1 participant