Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Autofill & databinding

Tags:

ember.js

I have this rather simple form which has a email and a password input field. For my webpage Google Chrome's autofill/save password has activated. Now whenever I load my webpage, Chrome autofills the email and password field (which is nice).

Problem is EmberJS doesn't seem to "see" these auto filled values. If I use this.get('userName') for example in the controller, ember returns me blank values.

In order to have ember "see" these autofilled values, I have to click on each {{input}} or tab through them and then ember begins to see it.

It's a very simple form really:

<div>
<form class="form-signin form-vertical" id="login-form" {{action "login" on="submit"}}>

    <h3 class="form-signin-heading text-center sf-primary-color">Please Login</h3>

    {{input class="form-control" name="email" placeholder="Email address" value=userName type="text" tabindex=1}}
    {{input class="form-control" name="password" placeholder="Password" value=password type="password" tabindex=2}}

    {{#if errorMessage}}
        <div class="alert alert-danger text-center sf-fade-in">{{errorMessage}}</div>
    {{/if}}

    <div class="well">
        You may login with <kbd>demo</kbd>/<kbd>demo</kbd>.
    </div>

    {{input type="submit" value="Log In" tabindex=3}}

</form>
</div>

I have created a fiddle as well. The problem is not reproducible in the fiddle, because no matter how many times I've run it. The browser does not offer to save the password.

It does sound like Ember's data binding is not detecting a browser autofilled {{input}}

As an aside, I had to use the trick outlined here in order to get these input fields to offer auto complete.

EDIT: I defined an observer like below and it is not fired when the site is first loaded and auto fill has done it's job.

    userNameChanged: function() {
        console.log('User Name Changed');
    }.observes('userName'),

Version Info follows:

DEBUG: ------------------------------- ember.js:3461
DEBUG: Ember      : 1.4.0 ember.js:3461
DEBUG: Ember Data : 1.0.0-beta.4 ember.js:3461
DEBUG: Handlebars : 1.3.0 ember.js:3461
DEBUG: jQuery     : 1.10.2 ember.js:3461
DEBUG: ------------------------------- 
like image 976
Code Poet Avatar asked Mar 11 '14 11:03

Code Poet


People also ask

What is browser autofill?

Autofill is a browser feature that allows people to save information (on the browser or the OS) and use it on web forms. autocomplete is an HTML attribute that provides guidelines to the browser on how to (or not to) autofill in fields in a web form.

How do I find my browser autofill?

Open your Chrome browser. Click on the three dots at the top right corner. Go to Settings, look for the Autofill section, and select Passwords. You will see a list of websites with usernames and passwords.

Where is the autofill in Chrome?

Choose Settings from the dropdown menu. On the left side of the Settings window, choose Autofill. Here you will find autofill settings that you can manage including passwords, payment methods, addresses and more. To manage password settings, under Autofill settings choose Passwords.


2 Answers

This is what I'm using ATM.

Ember.TextField.reopen({
    triggerEvents: function () {
        Ember.run.next(this, function () {
            this.$().trigger("change");
        });
    }.on("didInsertElement")
});

Modification of the solution found in the linked github issue thread.

(Updated according to @briangonzalez's suggestion)

like image 140
panta82 Avatar answered Oct 27 '22 04:10

panta82


Not perfect but functional solution:

Ember.TextField.reopen({

  fetchAutofilledValue: function() {
    var $textField = this.$();
    setTimeout( function(){
      $textField.trigger("change")
    }, 250);
  }.on('didInsertElement')

});
like image 30
chrmod Avatar answered Oct 27 '22 03:10

chrmod