Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button's disabled attribute cannot be set conditionally #25

Closed
bovisp opened this issue Apr 9, 2017 · 9 comments
Closed

Button's disabled attribute cannot be set conditionally #25

bovisp opened this issue Apr 9, 2017 · 9 comments
Assignees
Labels
Milestone

Comments

@bovisp
Copy link

bovisp commented Apr 9, 2017

Description

I am trying to conditionally trying to set the disabled attribute on a button, but this doesn't seem to be working. I should be able to do this by using m-literal:disabled and set that equal to a Boolean data property.

Steps to Reproduce

  1. Consider this Moon instance:
    var app = new Moon({
      el: "#app",
      
      data: {
        isDisabled: false
      },
      
      methods: {
        setDisabled () {
          this.set('isDisabled', ! this.get('isDisabled'))
        }
      }
    })

  1. ...and this HTML:
  <div id="app">
    <button
       class="button"
       m-literal:disabled="{{isDisabled}}"
       m-on:click="setDisabled"
    >Click to disable</button>
  </div>

Expected behavior

Before I even click the button to trigger the event, the above HTML should render to:

<button class="button">Click to disable</button>

As isDisabled is initially set to false, the disabled attribute should not appear at all.

On click, we should get the following:

<button class="button" disabled>Click to disable</button>

Actual behavior

Before I even click the button to trigger the event, the above HTML actually renders to:

<button class="button" disabled="false">Click to disable</button>

and the button appears as disabled.

This is probably not a bug. The bug may actually be the human (i.e. me). Suggestions?

@kbrsh kbrsh added the feature label Apr 10, 2017
@kbrsh kbrsh added this to the v0.9.0 milestone Apr 10, 2017
@kbrsh kbrsh self-assigned this Apr 10, 2017
@kbrsh
Copy link
Owner

kbrsh commented Apr 10, 2017

It's actually expected behavior at the moment, adding a boolean value to something will make the actual value of it that boolean. It doesn't conditionally render.

The only item that is treated special is classes, for example:

<!-- array of classes in m-literal applies all of them during a build -->
<h1 m-literal:class="['bar', 'baz']">Foo</h1>

<!-- object of classes conditionally adds them -->
<h1 m-literal:class="{bar: true, baz: false}">Foo</h1>

I guess I can add behavior to the prop diff to conditionally add elements if they are a boolean. It'll be coming in v0.9.0.

@kbrsh kbrsh closed this as completed in c92f581 Apr 10, 2017
@bovisp
Copy link
Author

bovisp commented Apr 10, 2017

@kingpixil Many thanks for your prompt replies over the last day. I'm a user of VueJS, but the speed and size of your framework is really intriguing to me.

Might this conditional HTML attribute rendering also extend to things such as "checked" and "selected"?

@kbrsh
Copy link
Owner

kbrsh commented Apr 10, 2017

@bovisp No problem! I can't thank you enough for the great feedback you give, it really helps. After I fix a couple more bugs, v0.9.0 will be out! 🎉

Yup! The conditional HTML attributes work for anything provided as a boolean, including component properties as well!

@bovisp
Copy link
Author

bovisp commented Apr 10, 2017

@kingpixil I'm happy to help. I'm in the process of creating some Moon examples using a codepen project. I'm basically retaking Laracasts' Vue 2.0 Step-by-Step and then Moon-ifying the resulting code. It will take me a while.

The project is in very rough shape right now and I only have four "hello world" type examples so far. They will be building in complexity as I move through the tutorials. I'll be renaming the HTML files and creating a landing page soon. The link is: https://codepen.io/tcdd/project/editor/ZoyVqA/

@bovisp
Copy link
Author

bovisp commented Apr 10, 2017

And I was able to get conditional classes working via m-literal:class with no issues using your API docs.

@kbrsh
Copy link
Owner

kbrsh commented Apr 11, 2017

That's super cool! Love the examples 👍

@brogier
Copy link

brogier commented Jul 12, 2017

Has this been fixed? Still having this issue with 0.10.0

@brogier
Copy link

brogier commented Jul 12, 2017

for (var nodePropName in nodeProps) {
        var _vnodePropValue = vnodeProps[nodePropName];
        if (_vnodePropValue === undefined || _vnodePropValue === false || _vnodePropValue === null) {
          node.removeAttribute(nodePropName);
        }
      }

node.removeAttribute(nodePropName); is trying to remove property m-literal:disabled instead of disabled. Any idea how this is possible?

@kbrsh
Copy link
Owner

kbrsh commented Jul 12, 2017

Ahh, thank you for bringing this to my attention. The condition was removed in some previous commit, it should be fixed in v0.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants