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

    most-jelly-15242

    10/02/2020, 2:45 PM
    The edit input also has several events attached to it
    Copy code
    <input id="edit-1" x-on:keydown.enter="if($event.target.value !== '') $event.target.blur()" x-on:edit="focus($event.target.id)" class="edit" name="task" value="one" hx-post="save" hx-trigger="blur" hx-vars="id:1">
  • m

    most-jelly-15242

    10/02/2020, 2:48 PM
    The
    edit
    event is triggered server-side using HX-Trigger so I can use that to run the
    focus
    function on the right input. This can be further simplified because the input doesn't need to be rendered for every task.
  • m

    most-jelly-15242

    10/02/2020, 2:49 PM
    If you see any opportunities to simplify the way the
    hx
    attributes are used, let me know!
  • l

    lively-beach-14291

    10/02/2020, 2:52 PM
    Well, it seems to work.
  • m

    mysterious-toddler-20573

    10/02/2020, 2:52 PM
    I think on the second one you could say
    hx-trigger='blur changed'
    maybe?
  • m

    mysterious-toddler-20573

    10/02/2020, 2:53 PM
    hmmm
  • m

    mysterious-toddler-20573

    10/02/2020, 2:53 PM
    I wonder if we can extend this to handle general matching in the trigger handler
  • m

    mysterious-toddler-20573

    10/02/2020, 2:54 PM
    e.g.
  • m

    most-jelly-15242

    10/02/2020, 2:55 PM
    blur changed doesn't work because the then the page doesn't update and it remains in "edit" state.
  • m

    mysterious-toddler-20573

    10/02/2020, 2:55 PM
    oh, it's only the enter key
  • m

    mysterious-toddler-20573

    10/02/2020, 2:55 PM
    yeah, let me think
  • m

    mysterious-toddler-20573

    10/02/2020, 2:56 PM
    i think the trigger syntax can be updated to help with this stuff, just thinking it through
  • m

    most-jelly-15242

    10/02/2020, 2:58 PM
    Alpine JS has these modifiers for the keydown event which let you listen for specific keys or key combinations (COMMAND-ENTER). Would be nice to have this natively. But even then, it should be possible to prevent a double request with "enter blur". And I am not sure how to deal with the focus thing without extra js.
  • m

    mysterious-toddler-20573

    10/02/2020, 2:58 PM
    hx-trigger="keydown(key:'enter') condition:value!=''"
  • m

    mysterious-toddler-20573

    10/02/2020, 3:00 PM
    yeah, the blur logic is pure client side stuff, so that would need to be hyperscript
  • m

    mysterious-toddler-20573

    10/02/2020, 3:00 PM
    what is the focus doing?
  • m

    most-jelly-15242

    10/02/2020, 3:01 PM
    when you double click a task, it shows the input to edit it and automatically adds the focus at the end of the value.
  • m

    mysterious-toddler-20573

    10/02/2020, 3:01 PM
    how is the edit event triggered?
  • m

    mysterious-toddler-20573

    10/02/2020, 3:01 PM
    more alpine?
  • m

    most-jelly-15242

    10/02/2020, 3:01 PM
    server side
  • m

    most-jelly-15242

    10/02/2020, 3:02 PM
    I listen for it with Alpine
  • m

    mysterious-toddler-20573

    10/02/2020, 3:02 PM
    there is a dblclickk event it looks like
  • m

    most-jelly-15242

    10/02/2020, 3:02 PM
    It's this
    x-on:edit="focus($event.target.id)"
  • m

    mysterious-toddler-20573

    10/02/2020, 3:03 PM
    that could be used to pull down the edit UI for the item
  • m

    most-jelly-15242

    10/02/2020, 3:03 PM
    Yes, double click sends an edit request. I show the edit input and send an HX-Trigger = 'edit' and listen to that to do the focus.
  • m

    mysterious-toddler-20573

    10/02/2020, 3:04 PM
    autofocus
    would work I think
  • m

    most-jelly-15242

    10/02/2020, 3:04 PM
    I tried it, but it puts the cursor at the beginning
  • m

    mysterious-toddler-20573

    10/02/2020, 3:04 PM
    ahhhh
  • m

    mysterious-toddler-20573

    10/02/2020, 3:05 PM
    we should put the cursor at the end for sure, that's a bug
  • m

    mysterious-toddler-20573

    10/02/2020, 3:05 PM
    i mean, that's apparently the default behavior, but htmx should fix that
1...454647...1146Latest