Form model doesn't update on autocomplete
I'm having problems with Safari 6.0 auto-complete on some simple forms on Angular 1.0.2.
When Safari uses auto-complete to fill in the form, Angular seems to be
unaware of the new characters that were entered by auto-complete.
Please see the attached image for an example.
To reproduce:
- Enter data into the form a few times so that auto-complete is activated.
- Then enter a few characters that triggers an auto-complete.
- Hit return.
- Compare the alert message with the contents of the input field.
I've created a jsFiddle that can be used to reproduce the problem: http://jsfiddle.net/msgilligan/5cynT/
I've seen a similar problem when Safari 6.0 or Chrome 22.0.1229.79 automatically fills in a password field that has a 'required' attribute. The form is not marked as valid and I have to go enter a space after the password and then delete it.
@blaise-io I am on parental leave right now for 1 1/2 more weeks. So it won't be before then...
@tbosch Kudos for putting your family first, it's good to see, and double thanks for working on a fix :)
Hello all, here is the initial polyfill that triggers a change event when the browser changes form fields without triggering a change event: https://github.com/tbosch/autofill-event
The polyfill will check for changes on document load and also when an input is left (only in the same form). However, you can trigger the check manually if you want to.
The project has unit tests as well as semi automatic tests, so we finally have a place to collect all the different use case together with the required browser settings.
Please note: This polyfill works with plain AngularJS apps, with AngularJS/jQuery apps but also with plain jQuery apps that do not use Angular.
Feedback welcome, but please as issues (or better PRs) on that new project!
Ok, I am closing this now. Please file any missing use case or bugs related to auto fill events in the new project https://github.com/tbosch/autofill-event
Thanks all!
@tbosch so it will not be build in Angular code, we should always include this file?
@jamm Yes, for now, we won't build this into Angular code. This is a bugfix for the browser, and also works without Angular (e.g. for plain jQuery apps).
@tbosch Thanks for your polyfill! You just totally ended my headaches.
This is working great if the form that I am using autofill with is the form that is displayed when I load the page. However, if I use ui.router to navigate to the form that is being autofilled, it doesn't work. I hope that makes sense!
I see the comment about the manual application:
$el.checkAndTriggerAutoFillEvent(): Execute the check for all DOM elements in the given jQuery / jQLite element.
I am not a javascript programmer, I work more on the backends. I have tried just about everything to try this command and can't get it to work. I assume that the $el is a variable that I need to substitute from my code? I am including jQuery, then angular. How do I call this manually?
-g
@lgfausak Try this: $('input').checkAndTriggerAutoFillEvent();
Thanks, that did the trick! Just to follow up for those that are as slow as me with regard to ng.
First, I had to put these in the top of my index.html file
Just doing that fixed the issue when a autofill page was directly loaded. But, if I navigated to an autofill page I still had an issue...
Here is my input form with name and password:
Then in the .js file which has my input form's submit handler: $scope.login = function() { $('input').checkAndTriggerAutoFillEvent(); ... then I just continue, the autofill worked in all cases at this point...
-g
Thanks to all of you guys! (My son helped me with the javascript. It turns out that all I needed to do was include jQuery. Being a backend programmer this wasn't obvious to me :-) ).
"My son helped me with the javascript", this phrase should be in a fact's wall!!! :D
tell me about it :-)
On Sun, Feb 9, 2014 at 1:29 PM, Marçal Juan Llaó [email protected]:
"My son helped me with the javascript", this phrase should be in a fact's wall!!! :D
Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/1460#issuecomment-34583390 .
Greg Fausak [email protected]
@lgfausak This should work out of the box, even with ui router. Could you create a sample app as plunker/jsfiddle to show the problem and create an issue in the new repo?
Does anyone else get this error?
Cannot read property '$viewValue' of undefined
@ProdigyView Could you create an issue on the new repo and also create a punker/jsfiddle to reproduce it?
I pass user name and password direct to my Service using jQuery, it's a worth workaround! =]
Please star this issue to get browsers to fix this natively: https://code.google.com/p/chromium/issues/detail?can=2&q=autofill&colspec=ID%20Pri%20M%20Iteration%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified&id=352527&thanks=352527&ts=1394783497
@evictor thanks! your solution works.
for anyone else looking here, http://stackoverflow.com/a/19854565/1225924 worked for me, and is a much simpler solution than backporting the fix if you are not on the latest release.
Cool for fix it.
elem.find('input, textarea, select').trigger('input').trigger('change').trigger('keydown');
scope.$apply(attrs.ngSubmit);
works
what's the different between
$timeout(function () {
elem.find('input, textarea, select').trigger('input').trigger('change').trigger('keydown');
});