I have a liveview page with a series of checkbox inputs. I noticed that if I dispatch an unrelated event using
phx-click to the server, all of the checkboxes lose their
checked state. Its as if liveview is re-rendering the entire page.
My understand of Liveview could be wrong, but I thought it diffed changes and only patched the DOM where new changes are coming in. The
phx-click I am dispatching is totally isolated from the checkboxes, so I am confused as to why my page seems to be re-rendering the checkboxes causing them to lose their
I’ve thought of a workaround that would include using
phx-change on the form containing the checkboxes and keeping state within the liveview of which checkboxes are selected. When I render the checkboxes I could compare this list of selected checkboxes from the liveview state to which checkbox is currently being rendered and mark it as
checked from there, but I’m hoping to understand why this is necessary.
My thinking tells me that since the checkboxes are not included in the updates coming from the original
phx-click there should be no reason the checkboxes are re-rendering and losing their state in the browser.
Thanks for the help! I can add some code if it’s helpful.