datastar icon indicating copy to clipboard operation
datastar copied to clipboard

data-on-click.outside problem

Open blinkinglight opened this issue 1 year ago • 1 comments
trafficstars

click on 0 should be RowID: 0, then 1 - 1 click on document should be outside. somehow outside works for 2 clicks and stops.


templ Test() {
	<!DOCTYPE html>
	<html lang="en">
		<head>
			<meta charset="UTF-8"/>
			<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
			<title>Document</title>
			<script type="module" defer src="https://cdn.jsdelivr.net/npm/@sudodevnull/datastar"></script>
		</head>
		<body data-store="{ row_id: '' }">
			<div>
				RowID: <span data-text="$row_id"></span>
			</div>
			<hr/>
			for i := range 10 {
				<button data-on-click={ fmt.Sprintf("$row_id = '%d';", i) } data-on-click.outside="$row_id = 'outside';">Click me { strconv.Itoa(i) }</button>
			}
			<hr/>
		</body>
	</html>
}

blinkinglight avatar Oct 04 '24 11:10 blinkinglight

you can't have to data-on-click's on the same element. it's a limitation of the data-* spec @blinkinglight

delaneyj avatar Oct 06 '24 15:10 delaneyj

i think problem could be that https://github.com/delaneyj/datastar/blob/main/packages/library/src/lib/plugins/attributes.ts#L325 nothing resets called. with 2 different fields it still works for 1st 2 times and then never shows me .outside

blinkinglight avatar Oct 07 '24 05:10 blinkinglight

https://alpinejs.dev/directives/on#stop https://alpinejs.dev/directives/on#outside

blinkinglight avatar Oct 07 '24 05:10 blinkinglight

Hmm, got a PR in mind? I'll have to play with it a bit to figure out the right approach. Thanks for bringing to my attention. What are you think in regards to the stop part and how it effects this?

delaneyj avatar Oct 07 '24 17:10 delaneyj