enough-petabyte-50314
03/01/2023, 12:33 AMenough-petabyte-50314
03/01/2023, 12:53 AMplain-kangaroo-26043
03/01/2023, 2:46 PMhx-indicator="none"
(i.e. disable a default hx-indicator) ?some-airline-73512
03/01/2023, 2:51 PMhtml
<input hx-post="..." hx-indicator="#none">
<!--hidden div for invisible hx-indicator-->
<div id="none"></div>
plain-kangaroo-26043
03/01/2023, 2:52 PMhx-swap=none
. I think hx-disinherit
might do the trick?some-airline-73512
03/01/2023, 2:53 PMplain-kangaroo-26043
03/01/2023, 2:54 PMplain-kangaroo-26043
03/01/2023, 2:54 PMsome-airline-73512
03/01/2023, 2:56 PMplain-kangaroo-26043
03/01/2023, 2:58 PMhx-disinherit="hx-indicator"
worksbland-coat-6833
03/01/2023, 3:20 PMhx-indicator=“none”
does it do what you want? The docs suggest that it’ll look for a none
element, which I’m guessing you don’t have?bland-coat-6833
03/01/2023, 3:20 PMplain-kangaroo-26043
03/01/2023, 3:21 PMbland-coat-6833
03/01/2023, 3:21 PMsome-airline-73512
03/01/2023, 3:21 PMplain-kangaroo-26043
03/01/2023, 3:21 PMhtmx-request
to the trigger element (so careful with any css you might have)some-airline-73512
03/01/2023, 3:22 PMplain-kangaroo-26043
03/01/2023, 3:22 PMsome-airline-73512
03/01/2023, 3:23 PMplain-kangaroo-26043
03/01/2023, 3:23 PMbland-coat-6833
03/01/2023, 3:25 PMplain-kangaroo-26043
03/01/2023, 3:26 PMsome-airline-73512
03/01/2023, 3:26 PMplain-kangaroo-26043
03/01/2023, 3:50 PMhx-indicator=this
which seems to do the same thing (i.e. applies htmx-request
to the trigger element)eager-agency-92101
03/01/2023, 11:57 PMhtml
<form hx-post="/post-form" hx-ext="json-enc">
<input type="text" name="person[0][name]">
<input type="text" name="person[0][age]">
<input type="text" name="person[1][name]">
<input type="text" name="person[1][age]">
<input type="text" name="person[2][name]">
<input type="text" name="person[2][age]">
</form>
Is there a way to transform the json like below before posting?
js
{
person: [
{name: "", age: ""},
{name: "", age: ""},
{name: "", age: ""},
]
}
limited-teacher-83117
03/02/2023, 6:09 AMlimited-teacher-83117
03/02/2023, 6:19 AMjson-enc
extensions it's really small:
js
htmx.defineExtension('json-enc', {
onEvent: function (name, evt) {
if (name === "htmx:configRequest") {
evt.detail.headers['Content-Type'] = "application/json";
}
},
encodeParameters : function(xhr, parameters, elt) {
xhr.overrideMimeType('text/json');
return (JSON.stringify(parameters));
}
});
Basically just listens for the event, changes the content type, and and runs the JSON.stringify
function. You could replace that line with a few lines that parse the number of the person, and build the object so that it's an array of similar properties. There's no reason you need to do that on the frontend thougheager-agency-92101
03/02/2023, 8:58 AMripe-action-67367
03/02/2023, 9:16 AMparameters
field and it will be serialized by the extensionpowerful-helmet-42757
03/02/2023, 7:30 PMtarget="_blank"
added programmatically on the front-end... Any way around this?