I'm running into an issue where my model will not update when the browser autofills the field. I've selected an answer by Ezekiel Victor which looks like what I need, but I'm having trouble implementing it.
angular.module('roomsApp.directives', []).directive('formAutofillFix', ['$timeout',
function ($timeout) {
return function(scope, elem, attrs) {
// Fixes Chrome bug: https://groups.google.com/forum/#!topic/angular/6NlucSskQjY
elem.prop('method', 'POST');
// Fix autofill issues where Angular doesn't know about autofilled inputs
if(attrs.ngSubmit) {
setTimeout(function() {
elem.unbind('submit').submit(function(e) {
e.preventDefault();
elem.find('input, textarea, select').trigger('input').trigger('change').trigger('keydown');
scope.$apply(attrs.ngSubmit);
});
}, 0);
}
};
});
I get an error on the line:
elem.unbind('submit').submit(function(e) {
In Firefox: elem.unbind(...).submit is not a function
In Chrome: Object [object Object] has no method 'submit'
After digging around online, the most common thing that causes this error is when an input field is named "submit", but mine is not suffering from that particular issue
<form form-autofill-fix ng-submit="login()" id="login-fields">
<input form="login-fields" ng-model="userLogin" type="email" name="username" ng-required/>
<input form="login-fields" ng-model="userPassword" type="password" name="password" ng-required />
<button form="login-fields" name="login"">Login </button>
</form>
I'd appreciate any insight into this.
References:
http://victorblog.com/2014/01/12/fixing-autocomplete-autofill-on-angularjs-form-submit/
"Submit is not a function" error in JavaScript