live_select
live_select copied to clipboard
"Value" component argument breaks normal form handling
LiveSelect and LiveView versions Newest
Describe the bug I have been using "value" option to override the default form handling. However, recently I've discovered that the way it's implemented in LiveSelect breaks normal form behavior.
Expected behavior There's no need for extra back-and-forth as the form value is already delivered to the client as part of the initial render.
Actual behavior When "value" option is set, the server pushes the value on initial render to the client, and the client triggers "change" events. Now, you may think that triggering "change" should be harmless. But there are multiple issues with it:
- It causes unnecessary server load - I actually observed my "change" event callback triggered 2 extra times on each page render.
- "change" is supposed to be triggered by the user. What happened to me is that I had form errors rendered on submit, with LiveSelect triggering the "change" and removing the errors (the errors are not rendered on form validation, hence the removal).
I think this behavior must be changed, or at least documented explicitly.