8

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.

3 Answers 3

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">
Sign up to request clarification or add additional context in comments.

Comments

5

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

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

3 Comments

This is horrible! (which is not your fault, thanks for pointing at it) - Any idea why it's like that? and whether there is a way to make it open for whatever I add?
Not all browsers support required, so the framework ships with a minimal set, letting developers add additional attributes if they know they will target only browsers that support it.
This might be a topic for Discourse, but really, I just think there is no point/benefit in limiting what the user can do with their markup (as long as it's not code, e.g. not Handlebars expressions). I'm guessing this is a side effect of some design limitation in the library, if it's meant to be this way as a feature, that'd be nothing but adding friction IMHO.
5

First you need to add support to the required attribute:

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

Then in your view:

{{view Ember.TextField required="required"}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.