Is it possible to set a boolean html attribute (no...
# compose-web
b
Is it possible to set a boolean html attribute (not property) with compose? attr("name", true.unsafeCast<String>()) sets it as name="", whereas it should set it as just name with no empty string value.
r
Isn't the convention for flag properties to do
$name="$name"
?
b
Haven't tried that yet, will give it a go and report back
s
attr("name", "true")
?
b
Nope, that one is read as true even if you pass in false value
a
I believe it’s because of this behaviour of
setAttribute
Can you specify your use case?
b
Setting
checked
attribute on input element. Here's the end result I'm chasing:
<input type="checkbox" checked></input>
And i need that to be an html attribute as opposed to property
a
We will take a look how to manage it.
Is workaround clear for you until that? using dom effect.
b
Yeah, but it's kinda ugly 😀
👌 1
u
Correct me if I'm wrong but boolean attribute with space is actually by spec a valid way to switch it "on". Not saying we shouldn't discuss API improvements, just want to see the whole picture
b
That might be true by spec, but many web frameworks don't follow it and demand empty attr without a value to work