I have a typical form to enter values for a changeset. The form takes the begin_date and end_date for an event. I want to inject a checkbox into the form that allows the user to tell me if the event begins and ends on the same date.
I can’t get that checkbox to raise it’s own handle_event. It keeps invoking the form’s phx_change=“validate”. I saw a post by @sfusato that mentioned using phx-update=“ignore” inside the input element as a way to get the element to bypass phx_change … but I can’t get it to work.
I tried wrapping the checkbox inside an independent but that didn’t work either. Phx_chage=“validate” still got invoked. What am I doing wrong?
One change that I’ll mention for others who might see this post: I had to remove phx_target: @myself because this was being called inside a LiveView versus inside a component.
I’m going to post this as the solution to show some additional tweaks to get this to work, but be sure to read the post from CMO because that provides a critical part of this solution.
I made the change mentioned below where I removed phx_target: @myself because this is in a LiveView
I added phx_update: “ignore” to avoid a weird behavior where the checkbox only works on the second click. This was the solution I found from @sfusato in another post. Here is the post that explains the race condition created if you don’t include phx_update: “ignore”