Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I extend the EmberJS handlebars input helpers to support attributes without values?

I'm currently using the Ember input helpers to render data bound form controls:

{{input class="form-control" type="email" value=email }}

This generates the following HTML:

<input id="ember502" class="ember-view ember-text-field form-control" type="email" value="[email protected]">

HTML 5 input controls support the required attribute on elements. This attribute has no value. Attempting to pass the value into the template causes a compilation error and using something like required=true will not function correctly since the attribute is not empty.

How can I modify the ember TextInput view to include attributes without values? I've attempted to subclass it but the API is preventing direct access.

like image 911
jhappoldt Avatar asked Nov 29 '13 21:11

jhappoldt


1 Answers

By default ember doesn't map all options passed to input view helper like html attributes. You can achieve this using attributeBindings.

Ember.TextSupport.reopen({
    attributeBindings: ['required']
});

Give a look in that fiddle to see this in action http://jsfiddle.net/marciojunior/hRx5E/

like image 130
Marcio Junior Avatar answered Nov 14 '22 22:11

Marcio Junior