DonAgo
DonAgo

Reputation: 61

Does backbone.stickit support autofill?

I have a problem with binding a simple login form to a model. The "autofill" event won't be recognized by stickit and therefore the view is not in sync with the model.

The html is pretty straight forward:

<form>
    <input id="username" type="text"/>
    <input id="password" type="password"/>
</form>

The view will be initialized with an empty model and bound in the render function. Here's an excerpt of the code:

bindings: {
    '#username': 'username',
    '#password': 'password'
},

...

initialize: function () {
    this.model = new Backbone.Model();
}

...

render: function() {
    this.stickit();
}

If I retrieve the value by calling $('username').val() in the initialize function, I get the proper autofill value.

Does anyone know a solution to this problem?

I didn't create an issue in the git repository, because I'm not sure, whether I'm doing something wrong and autofill works out of the box.

Thanks in advance!

Ago

Upvotes: 4

Views: 476

Answers (2)

Allan Bazinet
Allan Bazinet

Reputation: 1837

There seems to be no standardization as to how the browsers or plugins magically stuff the input fields on autofill; it seems that in most cases change events aren't issued, so the model will be out of sync with the view. We do the following prior to saving the login model:

this.$('input').change();

Basically, forcibly fire change events on any input, so the change handlers get executed for the fields, after which the model should match the view.

Upvotes: 1

user1934853
user1934853

Reputation: 337

Stickit does not currently support browser autofill. Here is the GitHub issue: https://github.com/NYTimes/backbone.stickit/issues/168

Upvotes: 1

Related Questions