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

Unused param not sent for hidden inputs in LV 1.0 #3620

Open
linusdm opened this issue Jan 8, 2025 · 1 comment
Open

Unused param not sent for hidden inputs in LV 1.0 #3620

linusdm opened this issue Jan 8, 2025 · 1 comment

Comments

@linusdm
Copy link
Contributor

linusdm commented Jan 8, 2025

Environment

  • Elixir version (elixir -v): 1.18.1
  • Phoenix version (mix deps): 1.7.18
  • Phoenix LiveView version (mix deps): 1.0.1

Actual behavior

After moving to LiveView 1.0 I encountered the following problem. We integrate flatpickr for date inputs using clients hooks (e.g. phx-hook).

This library dynamically generates an alternative form input element that allows interaction and hides the original input element (using the type="hidden" attribute).

After changing to the new way to track used inputs I noticed that inputs with this hook are never marked as unused. This makes the input immediately seem used after a handle_event cycle. In cases where the input is validated as required for example, this makes the input show up with its error markup and validation error, even though an unrelated input has triggered the validation while the date input is untouched.

I guess there are more JS libraries that use a similar pattern (adding an alternative input field, hide the original, and keep them in sync). All libraries using a similar pattern should see this change in behaviour with LV 1.0.

I see that hidden fields don’t get a companion parameter with the unused prefix by design: see here. There is also some reasoning about not sending the unused-parameters for hidden fields in this PR: #3244.

For an example integration see this gist of @mcrumm (which would also break with LV 1.0):
https://gist.github.com/mcrumm/88313d9f210ea17a640e673ff0d0232b

Expected behavior

Consider also adding the unused companion param for hidden inputs to allow this type of JS integration without breaking tracking of unused inputs.

@tmjoen
Copy link
Contributor

tmjoen commented Jan 8, 2025

Not sending _unused for hidden inputs were very helpful for us, since we have some huge forms with a lot of hidden inputs that generate a ton of extra noise on the wire, but I absolutely see the need in cases like this. Would be nice if you could opt-out of the _unused somehow?

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

No branches or pull requests

2 participants