最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding attributes to input element in Handlebars (used with Ember.JS 1.0) - Stack Overflow

programmeradmin0浏览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.

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.

Share Improve this question edited Feb 5, 2016 at 1:47 Meligy asked Aug 12, 2013 at 14:29 MeligyMeligy 36.6k11 gold badges89 silver badges114 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

I'm using Ember version 1.5.1 and required="required" seems to work fine now. This markup:

{{input class="form-control" value=firstName autofocus="autofocus" required="required"}}

...renders this:

<input id="ember392" class="ember-view ember-text-field form-control" autofocus="autofocus" required="required" type="text">

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

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

First you need to add support to the required attribute:

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

Then in your view:

{{view Ember.TextField required="required"}}
发布评论

评论列表(0)

  1. 暂无评论