LiveVIew’s phx_change event is bound to the form validation, causing the setting of input value to become invalid. Checkbox can only select one item
<%= f = form_for @changeset, "#",
id: "invite-form—drm-form",
phx_change: "validate",
phx_submit: "save" %>
<div style="margin-left:5%">
<%= label f, :'Subnet id:' %>
<%= for role <- @cluster[:subnet_data] do %>
<div>
<input name="recipient[test]" type="checkbox" >
<%= role %>
</div>
<% end %>
</div>
def handle_event(
"validate",
%{"recipient" => recipient_params},
%{assigns: %{recipient: recipient}} = socket
) do
IO.inspect("validate")
template = if(Map.get(recipient_params, "pipeline_template") == "live-drm", do: true, else: false )
pipeline_template = if(Map.get(recipient_params, "pipeline_template") == "live-drm-pp", do: true, else: false )
changeset =
recipient
|> Invite.change_invitation(recipient_params)
|> Map.put(:action, :validate)
{:noreply,
socket
|> assign(:changeset, changeset)
|> assign(:show_text, template)
|> assign(:show_task, pipeline_template)
|> assign(:update_value, recipient_params)
}
end
I want to pass the selected checkbox parameters as an array to the backend. Currently, I cannot select multiple checkboxes because I am bound to PHX_ Change event.
<%= text_input f, :task_name, placeholder: "" ,value: @value %>
When I input the next input, the default value set is always restored