Like I mentioned earlier, you shouldn’t need a separate phx-change="type-dropdown"
at the input level and its corresponding handle_event/3
. Instead, the parent form phx-change="validate"
and its corresponding handle_event/3
should be sufficient in updating the parent :form
which will then show/hide something within the same form.
Note that by specifying phx-change
at the input level, the phx-change
at the form level no longer gets called i.e. LiveView will no longer push a "validate"
event and instead only push "type-dropdown"
event. It’s not in addition to, but instead of.
Also, you can get the index off of the nested form struct as discussed in this post Inputs_for/4 collection indices - #6 by silverdr instead of using Enum.with_index
.