mercredi 30 novembre 2016

Binding HTML Input value in Ember v1.12 Component

I need to use an HTML input in a component and need the value to be bound.The input helper causes various bugs when used on certain mobile devices, so that cannot be used.

The input that works in Ember 1.13 or higher.

component/name-input.hbs

<input type="text" value= onChange=>

component/name-input.js

export default Ember.Component.extend({
    name: 'Jim',
    actions: {
        nameDidChange: function(value) {
            this.set('name', value);
        }
    }
});

How do I use an HTML input in Ember 1.12 and still maintain the functionality?

I tried something like this but the input value is not passed to component's action:

component/name-input.hbs

<input type="text" value= >

component/name-input.js

export default Ember.Component.extend({
    name: 'Dwight',
    actions: {
        nameDidChange: function(value) {
            this.set('name', value);
        }
    }
});

Here are two Twiddles, one in 1.13 that works as expected and one in 1.12 that does not work.

Twiddle - 1.13

Twiddle - 1.12




Aucun commentaire:

Enregistrer un commentaire