_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

trigger event only once

Open jet10000 opened this issue 3 years ago • 1 comments

            <select id="selects" _="
            on change log my.value
            if my.value is 'A'
            remove .hidden from #searchAInput
            add .hidden to #searchBInput
            send keyup to #searchAInput
            end
            if my.value is 'B'
            remove .hidden from #searchBInput
            add .hidden to #searchAInput
            send keyup to #searchBInput
            end"
                    class="border-0 rounded-l-3xl text-sm focus:ring-0 pl-4">
                <option>A</option>
                <option>B</option>
            </select>

            <input id="searchAInput" type="search" name="q" placeholder="TEST1"
                   class="rounded-r-3xl border-0 w-full md:w-6/12"
                   hx-get="{% url 'a_list_view' %}"
                   hx-trigger="keyup changed delay:500ms, search"
                   hx-target="#search-results" autocomplete="off">
            <input id="searchBInput" type="search" name="q" placeholder="TEST2"
                   class="rounded-r-3xl border-0 w-full md:w-6/12 hidden"
                   hx-get="{% url 'b_list_view' %}"
                   hx-trigger="keyup changed delay:500ms, search"
                   hx-target="#search-results" autocomplete="off">

Fired only once and then It can't fire.

jet10000 avatar Jul 10 '22 22:07 jet10000

You're using keyup changed in your hx-trigger. The keyup event you're sending is empty and will not change the input value, so it will not react.

Simulating an actual key press is probably too much work, instead you can use a custom event:

send search to #searchBInput
...
    hx-trigger="keyup changed delay:500ms, search"

dz4k avatar Aug 03 '22 10:08 dz4k