Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic ID doesn't work with template strings #540

Closed
tvandinther opened this issue May 21, 2024 · 1 comment
Closed

Dynamic ID doesn't work with template strings #540

tvandinther opened this issue May 21, 2024 · 1 comment

Comments

@tvandinther
Copy link

tvandinther commented May 21, 2024

I am trying to use a template string to make a dynamic reference to an ID. Unfortunately this doesn't work due to an unterminated string error. Here is a jsfiddle with an example and a workaround (using an intermediate variable).

My expectation is for any expression to be valid for use as a dynamic ID. Is this a bug or is this intended? If intended, what is the reasoning for the limitation?


<button id="foo" _="on click toggle [@hidden] on #{`test-${event's target.id}`}">
  Show/Hide
</button>
<div id="test-foo">
  Hello
</div>

<button id="bar" _="on click set id to `test-${event's target.id}` toggle [@hidden] on #{id}">
  Show/Hide
</button>
<div id="test-bar">
  Hello
</div>
@1cg
Copy link
Contributor

1cg commented Dec 18, 2024

yeah it's a bug in the tokenizer, but fixing it would be really ugly

for this you could say:

on click
  set idToToggle to `test-${the event's target's id}` 
  toggle [@hidden] on #{idToToggle}

as a workaround. Sorry about that.

@1cg 1cg closed this as completed Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants