How to code "disabled"?
jkleiser opened this issue · 2 comments
jkleiser commented
In my little toy project, which is just a single html file, I want to disable a button, depending on some condition. I obviously haven't found the right way to code that condition. Here is my code:
<button onclick='app.run("remove")' disabled="${arr.length < 2}">Remove Last</button>
This way, the button gets disabled no matter the length of arr
.
I just found this solution, however:
<button onclick='app.run("remove")' ${arr.length < 2 ? 'disabled' : ''}>Remove Last</button>
yysun commented
You are doing it the right way using HTML string.
I would do the same: https://glitch.com/edit/#!/apprun-html-buttons?path=index.html:1:0
yysun commented
BTW, if you are using lit-html:
<button @click=${()=>app.run("-1")} ?disabled=${state<1}>-1</button>
https://glitch.com/edit/#!/apprun-lit-html?path=index.html:1:0