yysun / apprun

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

Home Page:https://apprun.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to code "disabled"?

jkleiser opened this issue · comments

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>

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

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