Hi, I'm just wondering whether it's currently possible in Svelte to conditionally append a boolean attribute to a node, ie a value-less attribute whose existence/absence alone controls the behaviour of the node.
Example:
<select class="foo" disabled>
...
</select>
If-blocks within the tag don't seem to be allowed in this case; ternary expressions aren't being evaluated, so it seems the only possibility right now would be to wrap the entire node in an if-block. Or am I missing something?
For boolean attributes like disabled, you can just do disabled="{{whatever}}" and the disabled will be set or unset based on whatever. https://svelte.technology/guide#tags
Thanks a lot and excuse the GH issue, I don't know how I missed that!
Is this obsolete syntax? i.e. I know that svelte used to use double curly braces, but now use single braces. For me, this is relevant for field validation, where I want to conditionally add or not add the required attribute to input fields.
@johndeighan yes. It's from 2017 (Svelte v2).
The syntax would now be:
<select class="foo" disabled={yourBoolean}>
Most helpful comment
Thanks a lot and excuse the GH issue, I don't know how I missed that!