Code Monkey home page Code Monkey logo

autofill-event's Introduction

Build Status

Autofill event polyfill

This is a polyfill that fires change events when browsers autofill form fields without firing a change event. The implementation is generic so it works in any application that uses either jQuery and/or Angular.

Test page with manual tests

Install

  • bower install autofill-event

Usage

Add the script autofill-event.js after jQuery or Angular in your page.

This will do the following:

  • after DOMContentLoaded: check all input fields
  • a field is left: check all other fields in the same form

API (to manually trigger the check):

  • $el.checkAndTriggerAutoFillEvent(): Execute the check for all DOM elements in the given jQuery / jQLite element.

How it works

  1. Remember all changes to input elements by the user (listening for change events) and also by JavaScript (by intercepting $el.val() for jQuery / jQLite elements). That changed value is stored on the element in a private property.

  2. Checking an element for auto fill: Compare the current value of the element with the remembered value. If it's different, trigger a change event.

Dependencies

AngularJS or jQuery (works with either one or both)

Tests

Unit tests (Travis CI)

  1. npm install
  2. bower install
  3. npm install karma -g
  4. Run tests with jQuery: karma start test/unit/config/karma-jquery.conf.js
  5. Run tests with Angular: karma start test/unit/config/karma-angular.conf.js

Manual Tests (live version)

  1. npm install
  2. bower install
  3. scripts/webserver.js
  4. open the manual runner and follow instructions

Notes:

  • They need to be run with a webserver and without iframes, otherwise Chrome would not autofill username/password

autofill-event's People

Contributors

blowsie avatar jca258 avatar tbosch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autofill-event's Issues

In Safari 7, $ngModel is not updated on blur

Please see specific instructions to repro on this Plunkr.

This only happens on Safari 7 when "inline autofill" (which only affects the field in focus, as opposed to the autofill option that fills out all fields in the form) is triggered in a certain way.

Causes datepicker form elements to be marked dirty in AngularJS & AngularStrap

When there's a form element using AngularStrap's bs-datepicker autofill-event causes the element to be marked as dirty, Angular then sees the form as dirty too. Depending on the timing, the date may show as dirty immediately or only after you click on another field or two. Plunker showing this is here:
http://plnkr.co/edit/gYPSOaXARoHiCrkeTAjh?p=preview

Also seen with Angular 1.2.6 and with Angular-Strap 2.1.1. Firefox 32.0.3 & Chrome 37

Just guessing but somehow autofill-event is seeing the instantiation of the bs-datepicker element as an autofill event?

Firefox: Auto fill does not trigger on view changed

My Firefox version: 26.0
This is my test sample:
http://plnkr.co/edit/wZHXw4PCWolrDoTMw8nZ?p=preview

I copied the autofill-event.js to the plunkr for test.

There are 2 errors:

  • When document ready, triggered "DOMContentLoaded" , 200ms delay to trigger change event is not longer enough(I set the delay in the sample to 500ms works fine)
  • When I turn to index(another view), then back to sign in view, browser auto fills the inputs, but the event not trigger. I found that auofill is not checked when ui-view changed, so I tried to manually trigger autofill check in the controller, as: $rootElement.find('input').checkAndTriggerAutoFillEvent() also failed.

Is anything wrong in my code?

CDN it please!

What about adding the source to CDN ?

I guess there are cool services for free, i don't remember the name probably this is one of the best one https://github.com/cdnjs/cdnjs

this could be fantastic for the mass!!
thanks for your time

changing values in Angular scope

My stack is Django+Angular. I have login form with username and password.
Autofill is not changing my values in Angular scope in firefox 26.0.
I tried to do:

element.find('input[name="username"]').checkAndTriggerAutoFillEvent();
element.find('input[name="password"]').checkAndTriggerAutoFillEvent();
scope.init(); //just emptying the values

and it fixes the password field, but not the username field and I can't understand what the problem is.

Thanks, Alex A.

Firefox 29 not working on autofill Enter key

Hi, i'm using this polyfill but in Firefox 29.0 it won't work , if i autofill via tab or mouse its ok but if i autofill via enter key it doesn't works, any clue?

I'm on MacOSX using the latest Firefox version 29.0
thanks

Create new release with recent changes

I'm using autofill-event through bower on one of my projects and would like the fix for IE8. Instead of updating the file manually could you create a new release with the most recent commits so we can use bower update?

Is listening to radio inputs intentional?

On DOMContentLoaded this plugin is triggering a change event for my radio inputs which do have a value attribute, but not because the server filled in a value like an input, but because.. they're radio inputs.
I have a feeling autofill doesn't ever automatically choose a radio so those could be excluded, yes? Happy to send a PR but want to ask about this first.

Return $rootElement if no parent form is found

Since input elements can be used outside of form elements it would be nice if instead of an empty object findParentForm() returned the $rootElement. As it currently stands, none of the input elements are checked if there is no parent form.

Login autofill doesn't work in Firefox

The login form manual test cases fail for me in Firefox 26.0 in both Windows and Linux. Let me know if there's any additional info that could help with debugging.

Btw, thanks for this polyfill @tbosch!

Missing files in bower package

bower install
ls -la assets/vendor/autofill-event/
total 64
drwxr-xr-x  10 pronebird  staff   340 Sep 15 14:44 .
drwxr-xr-x   7 pronebird  staff   238 Sep 15 14:44 ..
-rw-r--r--   1 pronebird  staff   621 Sep 15 14:44 .bower.json
-rw-r--r--   1 pronebird  staff    38 Sep 15 14:44 .bowerrc
-rw-r--r--   1 pronebird  staff    36 Sep 15 14:44 .gitignore
-rw-r--r--   1 pronebird  staff   103 Sep 15 14:44 .gitmodules
-rw-r--r--   1 pronebird  staff  1099 Sep 15 14:44 LICENSE
-rw-r--r--   1 pronebird  staff  2011 Sep 15 14:44 README.md
-rw-r--r--   1 pronebird  staff   276 Sep 15 14:44 bower.json
-rw-r--r--   1 pronebird  staff   522 Sep 15 14:44 package.son

bower.json points to "autofill-event": "~1.0.0"

Input values in url security risk

When using firefox on a login page, I was having an issue where it was telling me that -webkit-autofill was not a valid selector. Because it this it would crash on login submit. The security risk is that I notices that it appended the input fields and their values to the end of the url when it failed. So had I pushed this to production, the user names and passwords would have been publicly exposed in the url. Leaving the high probability that the password would get logged in numerous places. Sorry, I do not have any screens because I was more concerned about getting this out of my app for now. I will update when I have reproduced it again in a sample app I can post.

Fires change events when no change

Sometimes this fires a change event even if there's no change, for example when an input field is ajax'd into the DOM

I change the triggerChangeEvent function to check if there was a previous value and match against it. I only use jQuery so it isn't going to be a straight copy-paste for you if you want it to work with angular as well.

function triggerChangeEvent(element) {
    var dochange = true;
    var value = $(element).val();
    if ($(element).attr('last-val') !== undefined) {
        if ($(element).attr('last-val') === value) {
            return;
        }
    } else {
        dochange = false;
    }
    $(element).attr('last-val', value);
    if (dochange) {
        var doc = window.document;
        var event = doc.createEvent("HTMLEvents");
        event.initEvent("change", true, true);
        element.dispatchEvent(event);
    }
}

Only issue I have had with the above code is the browser autocomplete for username and password fields, as that seems to be triggered at page load. So I do a settimeout for those particular fields.

fix(ie8): support IE8 attachEvent not working

ok, ie8's addEventListener is fixed. but it still not working on ie8.
form input change -> if click submit button -> not working
form input change -> enter key hit -> first time not working -> second time working.
oh...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.