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

    abundant-spring-38265

    01/11/2023, 10:34 AM
    Copy code
    <form hx-post="{% url 'inventory:inventory_device_validation_state' %}" hx-trigger="click">
                                            {% csrf_token %}
                                            <div class="form-check form-switch">
                                                {% if not device.validation_ready_state %}
                                                <input class="form-check-input" name="validation_state" type="checkbox" value="{{ device.id }}-1" role="switch">
                                                {% else %}
                                                <input class="form-check-input" name="validation_state" type="checkbox" value="{{ device.id }}-0" role="switch" checked>
                                                {% endif %}
                                            </div>
                                        </form>
  • a

    abundant-spring-38265

    01/11/2023, 10:35 AM
    what's interesting is that if i click on the toggled switch x number of times it eventually works :S
  • b

    boundless-vase-80440

    01/11/2023, 10:49 AM
    Why not js:// ?
  • p

    prehistoric-garden-45720

    01/11/2023, 12:42 PM
    @mysterious-toddler-20573, do you want me to open a GitHub issue for this?
  • l

    late-king-98305

    01/11/2023, 1:34 PM
    That was the reason behind my up-front caveat; if you've never dealt with them before, checkboxes don't POST the way you'd think they would. 🙂 Take a look at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/checkbox#value and read their description at the bottom of the "Value" section (just above the "Additional Attributes" heading). So, server-side, instead of checking for true/false, yes/no, etc., you'll check for "on" or None. Another gotcha with clicking, which may be what you're describing, is that sometimes the event fires before the state change occurs. In other words, if there's an unchecked box that you click, in an
    onClick
    event handler, looking up that element's
    checked
    attribute will return
    false
    . They aren't as intuitive as we would think they should be! As you noted, if you click it enough, you do end up getting the toggle behavior, but I would bet that if you were to query the state of that checkbox, it would be the opposite of what you expected.
  • l

    late-king-98305

    01/11/2023, 1:36 PM
    I wish I had better news - but, the good part is that it's consistently strange. So, if you can interrogate the values on the server, based on the state when you clicked, you can adjust the server's expectations, and take action/return content accordingly. Just know that it's not you going crazy, it's the implementation of HTML and JavaScript that's doing it!
  • m

    mysterious-toddler-20573

    01/11/2023, 2:47 PM
    sure, that would b e good
  • m

    mysterious-toddler-20573

    01/11/2023, 2:47 PM
    agree, should be
    js://
  • o

    orange-umbrella-16693

    01/11/2023, 2:53 PM
    Why not
    javascript:
    , like for anchor tags, or would that be too confusing?
  • g

    gorgeous-airport-54386

    01/11/2023, 2:56 PM
    no
  • a

    adventurous-ocean-93733

    01/11/2023, 3:15 PM
    I'd vote that only valid URI schemes should be used like this https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
  • a

    adventurous-ocean-93733

    01/11/2023, 3:18 PM
    And
    js://
    isn't a valid URI scheme
    g
    b
    • 3
    • 6
  • m

    mysterious-toddler-20573

    01/11/2023, 4:52 PM
    ah, yeah, I thought
    js://
    was the valid URI scheme, but we should do what the standard & HTML supports
  • b

    brash-machine-54411

    01/11/2023, 5:30 PM
    Probably a stupid question, but why is HTML not called HMML?
  • b

    boundless-vase-80440

    01/11/2023, 5:30 PM
    cause it is text?
  • b

    boundless-vase-80440

    01/11/2023, 5:31 PM
    not stupid question at all
  • b

    brash-machine-54411

    01/11/2023, 5:31 PM
    What is hypermedia then?
  • s

    salmon-oil-67352

    01/11/2023, 5:31 PM
    Thanks for the reply, i added "" to the head, but still have the same issue. I recorded the issue, when the main_content gets replaced, the scroll is still on the bottom, and then the scrolltop is triggered but too late or something
  • b

    boundless-vase-80440

    01/11/2023, 5:32 PM
    hmmm
  • b

    boundless-vase-80440

    01/11/2023, 5:33 PM
    I will defer to @mysterious-toddler-20573 for a proper answer
  • s

    salmon-oil-67352

    01/11/2023, 5:38 PM
    @hundreds-cartoon-20446 Oh but with
    Copy code
    htmx.on('htmx:beforeSwap', (event) => {
            if (event.detail.target.id == 'main_content') {
                htmx.config.scrollBehavior = 'auto';
                htmx.config.defaultSettleDelay = 0;
            }
        })
    It does work! Thanks!!
  • m

    mysterious-toddler-20573

    01/11/2023, 5:50 PM
    https://hypermedia.systems/book/hypermedia-reintroduction/#_what_is_hypermedia
  • m

    mysterious-toddler-20573

    01/11/2023, 5:51 PM
    hypertext is a type of hypermedia, and HTML is a specific hypertext, but other hypermedia types can participate in a hypermedia system (e.g. an image with clickable regions, a video that allows non-linear branching, etc.)
  • s

    salmon-oil-67352

    01/11/2023, 6:11 PM
    Whats the point of having defaultSettleDelay defaulting to 20?
  • m

    mysterious-toddler-20573

    01/11/2023, 6:17 PM
    it allows CSS transitions to occur
  • o

    orange-umbrella-16693

    01/11/2023, 6:52 PM
    Does the hx-ws extension/htmx support several swaps in a single request? As in, how would htmx react if this was the request response?
    Copy code
    html
    <div id="element1"><p>I'm new content</p></div>
    <img id="image1" src="/path_to/newimage.png">
  • b

    boundless-vase-80440

    01/11/2023, 8:08 PM
    use hx-swap-oob: e.g.:
  • b

    boundless-vase-80440

    01/11/2023, 8:09 PM
    @orange-umbrella-16693 are you doing a chat app?
  • o

    orange-umbrella-16693

    01/11/2023, 8:12 PM
    No, but something with similar functionality
  • o

    orange-umbrella-16693

    01/11/2023, 8:12 PM
    Wanted to see if I could rewrite my site - which is basically a live-updated table, via websockets - to htmx
1...978979980...1146Latest