Hyperscript behavior ceases to work after active search
I'm using hyperscript 0.9.14. I have a table of data in a form, with the first column in each row being a checkbox. There is a behavior defined in a .hs file and installed on the
I realised that by installing the behavior on the tbody element, this problem seems to go away. However, I think the question of how one can reassert/reload a behavior when a change occurs to the elements that it applies to still stands, as my form leverages infinite scrolling: i.e the number of records in the table will increase as the user scrolls down.
When this happens the behavior is applied (correctly) to the rows that were loaded in when either the screen was refreshed, or a search was instigated, but is not applied to rows added through infinite scrolling.
You basically have to reprocess the nodes that were added via AJAX(infinite scrolling). The node on which your behaviour is placed doesn't get replaced, so you'd have to "reinstall" the behaviour on htmx:afterSwap or other events. Have a look at this: https://hyperscript.org/docs/#install
In the last few sentences it says this:
If your HTML is received via AJAX or generated by scripts after initial page load, you need to call _hyperscript.processNode() to process the scripts on the new elements.
element.appendChild(newContent); _hyperscript.processNode(newContent); You can also call it from hyperscript itself
call _hyperscript.processNode(#new_element_id) Elements added by the put command are processed automatically; no need to call this function. Htmx does the same for all processed fragments.