Hi, I’m looking for the best practice to implement a form with two submit buttons in LiveView. If we consider the following example:
<%= i = form_for @changeset, "#", phx_submit: "save" %> <%= submit "Save" %> <%= submit "Save and add another" %> </form>
I would like to implement a different behavior (redirect to a different URL) when handling the “save” event, depending on which submit button was used.
At first I realised that adding name and value attributes to the submit buttons would pass these to the event handler as part of the form parameters but soon discovered that it wasn’t the case when using Chrome.
The proper way to do this in pure HTML forms seems to be to add a “formaction” attribute to the submit buttons, which overrides the “action” attribute on the form, allowing for submitting the form to a different URL. I couldn’t find a way to make this work with my LiveView form when submitting is managed with phx_submit.
Is there a good way to achieve this or is it a behaviour currently not supported by phoenix_html?