Element passing own name/value on trigger? #3272
-
|
I'm new. For 30 minutes or so, I couldn't get htmx working. A lot of trial and error later, I realized that triggered elements don't pass their own name/value via the AJAX request. To me this seemed to be the intuitive way of handling a single dataset: So, now I have at least two alternatives to do the same... This seems to be going against the idea of defaulting to the name/value-convention htmx is adopting. Or, I can add a hidden field within my triggered element with the name/value: This seems to add a lot of overhead HTML. Why isn't the first example default behaviour? E.g., placing a simple name/value-set within a button itself seems to be a lot cleaner and easier to understand than either of the two alternatives... Anyway, my two cents. Perhaps it's supposed to work this way and I simply borked it... |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
Hey, could you tell us what htmx version you are using ? If I try the exact setup you described, it works, you can see it on this JSFiddle <script src="https://unpkg.com/[email protected]"></script>
<button hx-get="/something" name="id" value="1">Click me!</button>When I click on the button, the request URl properly includes the id parameter: Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
I'm using the latest (2.0.4) and it certainly does help. I will try to replicate when I get the time, thank you for answering. |
Beta Was this translation helpful? Give feedback.
-
|
So, I realize the problem now. In an effort to simplify my problem, I used a button as an example element. The original problem arose from me trying to trigger a Any way to enable this? Why isn't this a default feature? |
Beta Was this translation helpful? Give feedback.

Oh ok, the issue is that you define a
nameandvalueon non-input elements, which isn't a standard practice.You can see the list of tags supporting the
valueattribute on this MDN page for instance.You can see on the <button> element doc that it supports
name/valuein its attributes list, while the <tr> doc doesn't include it, nor does the <div> docformattribute. Try to use forms, buttons, inputs as much as possible to benefit …