We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Put `phx-change` inputs inside a form
almirsarajcic
Put every input with its own phx-change binding inside a form. Outside one, the markup looks wired, but LiveView will not send the event.
<!-- Broken: this change never reaches handle_event/3 -->
<input name="query" phx-change="search" />
<!-- Fixed: prefer the binding on the form -->
<form id="search" phx-change="search">
<input name="query" />
</form>
Putting phx-change on the form sends all of its fields when any input changes. The callback also receives _target, so it can identify the field that triggered the event.
An individual input may have its own phx-change when it needs a separate event or phx-target. It still has to live inside a form.
If a LiveView input appears to ignore typing without raising or logging anything, check its form ancestor before debugging the handler.
copied to clipboard