javascript - How do I extend the EmberJS handlebars input helpers to support attributes without values? - Stack Overflow

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

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 pilation 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.

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 pilation 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.

Share Improve this question asked Nov 29, 2013 at 21:25 jhappoldtjhappoldt 2,5261 gold badge21 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

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/marciojunior/hRx5E/

In my case using only attributeBindings did not help. I wanted to add an empty download HTML attribute to an a tag, but it was skipped. What I had to do was that I needed to set also the download property to an empty string.

In such a case try to use instead of this:

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

this snippet:

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

Maybe it will help ;-)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744347776a4569791.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信