0

I had the following action in my html:

<a href="#" class="list-group-item" disabled {{action addVisibilityService target="view"}}>
   element
</a>

and I have the function to handle this action:

addVisibilityService : function(element){
    console.log("I've been called");
},

but the problem is that this action is called when is disabled. So I was wondering how to avoid that?

Thanks

Juan Jardim
  • 2,232
  • 6
  • 28
  • 46
  • 1
    This wont work. You may need to use a button instead of an anchor. Here more information https://github.com/emberjs/ember.js/pull/2240 – blessanm86 Aug 12 '14 at 09:37

1 Answers1

1

It seems that HTML links cannot be disabled portably (eg How to disable HTML links also plenty other posts). What you can do is use the {{if}} helper and present it as simple text based on a certain state.

http://emberjs.jsbin.com/sefabibayile/1/edit

hbs

<script type="text/x-handlebars" data-template-name="index">
    <i>if value less than 3 characters link disabled</i>
    {{input value=someProp}}
    <br/>
    {{#if somePropOk}}
    <a href="#" class="list-group-item" {{action addVisibilityService target="view"}}>
   element
</a>
{{else}}
<span style="font-style:italic;color:grey">element</span>
{{/if}}


  </script>

js

App.IndexController = Em.Controller.extend({
   someProp:"test",
  somePropOk:function(){return this.get("someProp").length>3;}.property("someProp")
});
Community
  • 1
  • 1
melc
  • 11,523
  • 3
  • 36
  • 41