htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Submit button values are not sent

Open azmeuk opened this issue 2 years ago • 1 comments

On a simple form, the name and value of a <button type="submit"> button are not sent.

<form>
    <input type="text" name="text-field" value="input OK">
    <button type="submit" name="submit-button" value="foobar" hx-target="#results"
  hx-post="/echo/json">button KO</button>
</form>

<code id="results"></code>

You can check this fiddle, and inspect the requests to observe this behavior: https://jsfiddle.net/azmeuk/7ztxd820/54/

Using hx-include on the button does not send the data either so it cannot be used as a workaround, but I could manage to achieve what I want with hx-vals.

Might be related to #970 #971 #1120 #1337

azmeuk avatar Jun 21 '23 09:06 azmeuk

Submitted a PR that addresses this issue.

In the meantime, for current & older versions, even though it may not be what you want, it turns out that putting the hx-post (and hx-trigger) on the form itself, correctly includes the clicked button's value, if of course such workaround is possible in your situation

Telroshan avatar Jul 10 '23 14:07 Telroshan

Fixed since 1.9.4 Thank you!

azmeuk avatar Aug 27 '23 14:08 azmeuk