Reputation: 4222
i'm trying to bind two attributes to an Ember textfield, but it doesn't work.
{{input type="text" value=name class="uk-width-1-1" placeholder="Name" required="" }}
How can I bind an "error" class to this textfield when errors.name
is true?
Upvotes: 3
Views: 1390
Reputation: 357
what you are looking to do is as follows:
{{input type="text" value=name classBinding=":uk-width-1-1 errors.name:error" placeholder="Name" required=""}}
there is no need for a computed property here as long as error.name is truely a boolean value. in classBindings :uk-width-1-1 will always print and error will only be there if errors.name is true.
Just for reference, say you had a error and non-error class you wanted to use. You could do errors.name:error:non-error which would have error when errors.name is true and non-error when it is false.
Upvotes: 7
Reputation: 6709
You could change it to:
{{input type="text" value=name classBinding="textFieldClasses" placeholder="Name" required="" }}
end in your view define a computed property along the lines of:
textFieldClasses: function() {
var class = "uk-width-1-1";
if (this.get('controller.content.errors.name')) class += "error";
return class;
}.observes('controller.content.errors.name'),
Upvotes: 1