https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • e

    enough-petabyte-50314

    03/01/2023, 12:33 AM
    maybe that's intentional
  • e

    enough-petabyte-50314

    03/01/2023, 12:53 AM
    Yes. I have had this thought multiple times in the few weeks Ive been using htmx
  • p

    plain-kangaroo-26043

    03/01/2023, 2:46 PM
    quick question: is there some way to do
    hx-indicator="none"
    (i.e. disable a default hx-indicator) ?
  • s

    some-airline-73512

    03/01/2023, 2:51 PM
    Copy code
    html
    <input hx-post="..." hx-indicator="#none">
    <!--hidden div for invisible hx-indicator-->
     <div id="none"></div>
  • p

    plain-kangaroo-26043

    03/01/2023, 2:52 PM
    sure...but just wondered if there was an equivalent to
    hx-swap=none
    . I think
    hx-disinherit
    might do the trick?
  • s

    some-airline-73512

    03/01/2023, 2:53 PM
    No. The code works, no need to look for something more
  • p

    plain-kangaroo-26043

    03/01/2023, 2:54 PM
    yes it works, seems a bit hacky though
  • p

    plain-kangaroo-26043

    03/01/2023, 2:54 PM
    adding an element that's never used
  • s

    some-airline-73512

    03/01/2023, 2:56 PM
    Don't worry:)
  • p

    plain-kangaroo-26043

    03/01/2023, 2:58 PM
    yep
    hx-disinherit="hx-indicator"
    works
  • b

    bland-coat-6833

    03/01/2023, 3:20 PM
    If you set
    hx-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?
  • b

    bland-coat-6833

    03/01/2023, 3:20 PM
    Hacky but for a different reason 😂
  • p

    plain-kangaroo-26043

    03/01/2023, 3:21 PM
    yes. It raises an error in the console though.
  • b

    bland-coat-6833

    03/01/2023, 3:21 PM
    Ah. Fair enough.
  • s

    some-airline-73512

    03/01/2023, 3:21 PM
    Hiding indicator and inheritance - those are orthogonal features. One shouldn't be solved by the other. If you decide to get rid of inheritence? (because of project coding conventions or because htmx 2.0 changes something), then your solution will break
  • p

    plain-kangaroo-26043

    03/01/2023, 3:21 PM
    hx-disinherit works but it will apply
    htmx-request
    to the trigger element (so careful with any css you might have)
  • s

    some-airline-73512

    03/01/2023, 3:22 PM
    Yes you get the result that you want, but it's a side effect
  • p

    plain-kangaroo-26043

    03/01/2023, 3:22 PM
    hx-disinherit will cancel any config set at a higher level, which is exactly what I want.
  • s

    some-airline-73512

    03/01/2023, 3:23 PM
    You do you. If it's how you do the work, then I'm 100%. Everyone got his own style
  • p

    plain-kangaroo-26043

    03/01/2023, 3:23 PM
    so yes, I might decide to get rid of inheritance, but in this particular project it's not a concern.
  • b

    bland-coat-6833

    03/01/2023, 3:25 PM
    Disinherit seems like the natural way to do this? It’s getting inherited which isn’t what you want so turn it off?
  • p

    plain-kangaroo-26043

    03/01/2023, 3:26 PM
    exactly. It does exactly what it's supposed to, which is to cancel out (as opposed to override) anything you set at a higher scope
  • s

    some-airline-73512

    03/01/2023, 3:26 PM
    Yeah it's a stylistic discussion now, I don't like those. Everything is good guys
  • p

    plain-kangaroo-26043

    03/01/2023, 3:50 PM
    you can also just do
    hx-indicator=this
    which seems to do the same thing (i.e. applies
    htmx-request
    to the trigger element)
  • e

    eager-agency-92101

    03/01/2023, 11:57 PM
    For a form post
    Copy code
    html
    <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?
    Copy code
    js
    {
      person: [
        {name: "", age: ""},
        {name: "", age: ""},
        {name: "", age: ""},
      ]
    }
  • l

    limited-teacher-83117

    03/02/2023, 6:09 AM
    Yes but (as far as I know) you're going to have to do it yourself
  • l

    limited-teacher-83117

    03/02/2023, 6:19 AM
    If you look at the actual body of the
    json-enc
    extensions it's really small:
    Copy code
    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 though
  • e

    eager-agency-92101

    03/02/2023, 8:58 AM
    Thank you very much. Let me give it a try
  • r

    ripe-action-67367

    03/02/2023, 9:16 AM
    https://htmx.org/events/#htmx:configRequest is the way to transform message content. You can parse the parameters in the handler and construct them into object. Then you pass this object further in
    parameters
    field and it will be serialized by the extension
  • p

    powerful-helmet-42757

    03/02/2023, 7:30 PM
    I looks like HTMX doesn't care about a
    target="_blank"
    added programmatically on the front-end... Any way around this?
1...105410551056...1146Latest