Skip to content

Hyperscript behavior ceases to work after active search #638

@andrewah64

Description

@andrewah64

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

tag. Users can filter the contents of the table through an active search feature. This is implemented in HTMX and it swaps the tag out for new HTML based on the results of the search. The issue is that the behavior reacts to events correctly on the page's first load, but ceases to work following a search.

Is there a way to reassert a behavior following a change to a page's DOM?

<form hx-swap="none" _="install CheckBoxDataGrid">
	<table>
		<thead>
			<tr>
				<th>
					My checkbox
				</th>
			</tr>
		</thead>
		<tbody id="key-aur-inf-res"> <!-- active search swaps this out -->
			<tr>
				<td>
					<input type="checkbox" name="key-aur-mod-aauk-id" value="261">
				</td>
			</tr>
		</tbody>
	</table>
</form>
behavior CheckBoxDataGrid
	on click from <input[name="key-aur-mod-aauk-id"] /> in me
		log 'clicked checkbox'
	end
end

I've put a video of this below. On the first page load, the "on click" event handler fires, and button's text on the bottom right corner of the screen changes when checkboxes are selected. However, following an active search the event handler doesn't fire and the text doesn't change.

Behavior2.webm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions