"Not" Operator Inside a Handlebars Template
Take the following example which disables a button if a checkbox is not
checked and enables it when checked:
Handlebars:
<form {{action "register" on="submit"}}>
{{input type="checkbox" checked=isAgreed}}
{{input type="submit" value="Register" class="btn btn-primary"
disabled=isNotAgreed}}
</form>
Javascript:
App.ApplicationController = Ember.ObjectController.extend({
content:{
isAgreed:false
},
isNotAgreed:function(){
return !this.get('isAgreed');
}.property('isAgreed'),
actions:{
register:function(){
alert("registered");
}
}
});
As demonstrated in this JSBin.
I am wondering if there is a cleaner way of doing this. For example
removing the isNotAgreed observable property and just using something in
my handlebars template like {{input type="submit" value="Register"
disabled=!isAgreed}}. Is there a way to do this?
No comments:
Post a Comment