Rick Moss
Rick Moss

Reputation: 926

add a name attribute to a Ember.TextField?

Its been a long day and this is probably extemely simple but how do i add a name attribute to a Ember.TextField ?

I want to do something like this :

{view Ember.TextField valueBinding="your_name" placeholder="Your name" name="your_name"}}

This works with the placeholder but ignores the name.

Any ideas ??

thanks Rick

Upvotes: 3

Views: 4915

Answers (4)

sandstrom
sandstrom

Reputation: 15082

This will solve your problem. However, I would suggest not doing this. The idea behind ember is to keep information such as this out of the DOM.

Ember.TextField.reopen({
  attributeBindings: ['name']
});

Upvotes: 0

pangratz
pangratz

Reputation: 16143

The name attribute is not bound by default, see

As a workaround, you could create your own TextField, see http://jsfiddle.net/fkPzr/

App.TextField = Ember.TextField.extend({
    init: function() {
        this._super();
        // get attributeBindings and add 'name'
        var attributeBindings = this.get('attributeBindings');
        attributeBindings.pushObject('name');
        this.set('attributeBindings', attributeBindings);
    }
});

​UPDATE:

Since attributeBindings is declared as a concatenated property* the TextField can be simplified, see http://jsfiddle.net/cRhcg/:

App.TextField = Ember.TextField.extend({
    attributeBindings: ['name']
});

*a concatenated property does not override the property of an extended object but the existing values from the super object are concatenated. Makes sense? Here's an example

Upvotes: 8

Jaco Joubert
Jaco Joubert

Reputation: 1

If you simple want to have the option to specify a name attribute you can do it using attributeBindings.

{view Ember.TextField valueBinding="your_name" placeholder="Your name" attributeBindings="name" name="your_name"}}

Upvotes: -1

Thomas Bartelmess
Thomas Bartelmess

Reputation: 1111

It doesn't work because Ember.TextField does not expose this a attribute binding.

From Ember.TextField

attributeBindings: ['type', 'value', 'size'],

plus the ones from the mixin:

attributeBindings: ['placeholder', 'disabled', 'maxlength'],

To bind the name property, create an own subclass that adds 'name' to the attribute bindings

Upvotes: 2

Related Questions