Handling events in Phoenix LiveView

Hi, If in the next code, I would like to know if it is a bad practice the handling of the submit event. In that case, is there any other alternative code?

<form submit="save_submit" change="validate">
	<form id="form1" submit="save_submit" change="validate">
	</form>
	<form id="form2" submit="save_submit" change="validate">
	</form>
</form> 
def handle_event("save_submit", _params, socket) do
  # Submission logic for the parent form
  {:noreply, socket}
end

def handle_event("save_submit", %{"id" => "form1"}, socket) do
  # Submission logic for the child form 1
  {:noreply, socket}
end

def handle_event("save_submit", %{"id" => "form2"}, socket) do
  # Submission logic for the child form 2
  {:noreply, socket}
end

You shouldn’t nest form elements.

Take a look here: How to structure a web form - Learn web development | MDN

I’ve never done this myself but it has been discussed before. Have a look here:

I really appreciate it! I will change the code which I received structured like that and I have a problem with one of the modals. That should be the diagnose.
Thank you!

1 Like