4

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

Kersten
  • 1,662
  • 3
  • 16
  • 28
DonAgo
  • 61
  • 4
  • By "autofill" are you referring to another plugin or stickit's initialization process where the bound view element is initialized with the model's attribute value? – user2095627 Jun 18 '13 at 14:34
  • I'm referring to the browser mechanism which stores passwords and address data and automatically sets values in the input fields after the page has been loaded. – DonAgo Jun 21 '13 at 05:39
  • Yes, can confirm that's an issue – Jackie Chan Oct 25 '13 at 01:22

2 Answers2

1

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

user1934853
  • 337
  • 1
  • 2
  • 10
1

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.

Allan Bazinet
  • 1,752
  • 15
  • 15