kbrsh / moon

🌙 The minimal & fast library for functional user interfaces
https://moonjs.org
MIT License
6k stars 200 forks source link

Boolean attributes #238

Closed nathnolt closed 5 years ago

nathnolt commented 6 years ago

It doesn't seem to be possible to set boolean arguments based on state.

Example

<input disabled>

but having disabled based on state, so something like

<input ={disabledinput?'disabled':''}>

I want this for select options.

If this is in fact possible, then it wasn't clear to me from reading the docs (Or I missed it).

Thank you.

s-melnikov commented 6 years ago
<script type="text/mvl" id="template">
    <input If={disabled} type="text" disabled/>
    <input Else type="text"/>
    <button @click={toggle()}>Toggle</button>
  </script>

  <script>
    Moon({
      root: "#app",
      view: document.getElementById("template").innerHTML,
      disabled: false,
      toggle() {
        this.update({disabled: !this.disabled});
      }
    });
  </script>