Phx-update="ignore" not working on checkbox inside changeset form

UPDATE for anyone who reads this post:

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.

The final piece of code that works is this:

<%= checkbox f, :same_date, phx_update: "ignore", phx_change: "same_date_selected", checked_value: "true" %>

CHANGES:

  1. I made the change mentioned below where I removed phx_target: @myself because this is in a LiveView
  2. 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”
2 Likes