vicenrele
vicenrele

Reputation: 971

How pass parameter in action of handlebars input component? Using Ember.js

I need to use this input component:

{{input type="textarea" value=fileName class="field" action="setFileName" on="key-press"}}

But I have to pass a parameter.

I don't want to do:

<input type="textarea" {{bind-attr value=fileName}} class="field" {{action 'setFileName' param on="keyPress"}}

Upvotes: 0

Views: 1144

Answers (1)

GJK
GJK

Reputation: 37369

Here's a way you could extend the built-in component to do what you want:

export default Ember.TextField.extend({
    sendAction: function(name) {
        if (name === 'action') {
            return this._super('action', this.get('value'), this.get('otherArgument'));
        } else {
            return this._super.apply(this, arguments);
        }
    }
});

You could then use it like this:

{{custom-input otherArgument=someValue action='callback'}}

Then, do this to capture the action:

actions: {
    callback: function(value, otherArgument) {
        // value is the text in the input
        // otherArgument is the `someValue` that you passed in
    }
}

Upvotes: 1

Related Questions