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

    flaky-energy-47039

    01/07/2023, 12:34 PM
    I am starting to use htmx; trying to send a post request on button click. The button is not included in a form, but I want it to send post data, lets say, id = 428
  • f

    flaky-energy-47039

    01/07/2023, 12:35 PM
    Here is the button code, but it sends nothing:
  • f

    flaky-energy-47039

    01/07/2023, 12:35 PM
    What am I doing wrong?
  • a

    adventurous-ocean-93733

    01/07/2023, 1:24 PM
    hx-include
    is a css selector for a form element. Maybe you are looking for
    hx-vals
    https://htmx.org/attributes/hx-vals/
  • f

    flaky-energy-47039

    01/07/2023, 1:56 PM
    Thanks @adventurous-ocean-93733 . Trying this code, but still it does not work:
  • f

    flaky-energy-47039

    01/07/2023, 1:57 PM
    The Request tab in Firefox Developer tools for this request is empty and I do not get any post data on the server...
  • f

    flaky-energy-47039

    01/07/2023, 2:08 PM
    for now, I am simply transmitting all the needed data in the url, as you can see...
  • f

    flaky-energy-47039

    01/07/2023, 2:15 PM
    oh, I am having this error in the Console: SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data ...
  • f

    flaky-energy-47039

    01/07/2023, 2:32 PM
    so it is quote style that is wrong, I presume; will have to change that, but cannot at present, since the button currently is generated by php code and will only use outer double quotes...
  • a

    adventurous-ocean-93733

    01/07/2023, 2:45 PM
    Yes it’s strict JSON so must be hx-vals='{"myVal": "My Value"}'
  • a

    adventurous-ocean-93733

    01/07/2023, 2:49 PM
    But maybe you could also try escaping it? Or prefix if with
    js:
    as per example at https://htmx.org/attributes/hx-vals/
  • f

    flaky-energy-47039

    01/07/2023, 4:06 PM
    Oh, thanks, prefixing it with js: helped!
  • f

    flaky-energy-47039

    01/07/2023, 4:06 PM
    finally I am getting post requests to work!
  • r

    rich-television-50179

    01/08/2023, 12:39 AM
    Awesome!
  • b

    bland-coat-6833

    01/08/2023, 9:21 AM
    https://changelog.com/podcast/521 Rails-specific but this is someone preaching the Hypermedia Gospel. @mysterious-toddler-20573 probably needs to point him at the book
  • r

    refined-waiter-90422

    01/08/2023, 11:47 AM
    Awesome episode
  • s

    salmon-oil-67352

    01/08/2023, 12:31 PM
    Hi guys, i seem to have forgotten how to scroll to the top of the page after a form is submitted with HTMX?
  • s

    salmon-oil-67352

    01/08/2023, 12:39 PM
    Found it:
    hx-swap="outerHTML show:#body-div:top"
  • s

    salmon-oil-67352

    01/08/2023, 1:37 PM
    All the links on my webpage are hx-boosted
    <body hx-boost="true">
    . The links look like this:
    <a href="/orders" hx-target="#main_content">
    Whenever i click a link, and view the pagesource of that link in chrome, i only see what is inside main_content. The , footers, and everything that is not inside main_content is not there, everything on the fronted is good still. Is this normal behaviour?
  • r

    rich-television-50179

    01/08/2023, 7:55 PM
    What is the
    hx-indicator
    usually used for?
  • s

    some-solstice-89459

    01/08/2023, 7:55 PM
    showing loading icons
  • s

    some-solstice-89459

    01/08/2023, 7:56 PM
    the indicator will be shown until the request is not completed
  • r

    rich-television-50179

    01/08/2023, 7:57 PM
    And the indicator will show in the
    hx-target
    ?
  • s

    some-solstice-89459

    01/08/2023, 7:58 PM
    Copy code
    <div>
        <button hx-post="/example" hx-indicator="#spinner">
            Post It!
        </button>
        <img  id="spinner" class="htmx-indicator" src="/img/bars.svg"/>
    </div>
  • s

    some-solstice-89459

    01/08/2023, 7:58 PM
    here for example
  • s

    some-solstice-89459

    01/08/2023, 8:00 PM
    the img will be only visible while the request is not completed
  • r

    rich-television-50179

    01/08/2023, 8:00 PM
    Ah okay. I'll have to try it out.
  • r

    rich-television-50179

    01/08/2023, 8:03 PM
    Thank you
  • l

    late-king-98305

    01/08/2023, 10:27 PM
    Looks good. This is my first time seeing Thymeleaf templates, so that took me a bit to get, but I see where you're doing inline edits, templates to replace table rows, etc. 🙂
  • l

    late-king-98305

    01/08/2023, 10:32 PM
    That is exactly the behavior you'd expect. You don't have to replace the whole page; htmx replaces
    #main_content
    for you, making the network payload smaller, and keeping the page from having to reload styles / scripts / fonts / etc. 🙂
1...974975976...1146Latest