Search code examples
javascriptember.jshandlebars.js

Adding attributes to input element in Handlebars (used with Ember.JS 1.0)


Let's say I have something like:

{{input value=someModel }}

And then I want to add the simple required HTML 5 attribute to the input.

How would I do that?


Note that I tried the following variations without success:

{{input value=someModel required }} <!-- doesn't parse -->

{{input value=someModel required='required' }} <!-- doesn't render the attribute -->

{{view Ember.TextField valueBinding=someModel 
    required='required' }} <!-- doesn't render the attribute -->

<input required {{bindAttr value=someModel}}
     /> <!-- doesn't update the model, as expected -->

Update: This question was for Ember 1.0.


Solution

  • To globally add support for additional attributes you can reopen Ember.TextField

    http://emberjs.com/api/classes/Ember.TextField.html