Skip to content

Instantly share code, notes, and snippets.

@singhmohancs
Created January 19, 2018 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singhmohancs/f93412110f8ab40b0079faae6c91e48a to your computer and use it in GitHub Desktop.
Save singhmohancs/f93412110f8ab40b0079faae6c91e48a to your computer and use it in GitHub Desktop.
Fix autocomplete (autofill) form in Angular
angular.module('A').directive('formAutofillFix', function ($timeout) {
return function (scope, element, attrs) {
element.prop('method', 'post');
if (attrs.ngSubmit) {
$timeout(function () {
element
.unbind('submit')
.bind('submit', function (event) {
event.preventDefault();
element
.find('input, textarea, select')
.trigger('input')
.trigger('change')
.trigger('keydown');
scope.$apply(attrs.ngSubmit);
});
});
}
};
});
<form ng-submit="submitLoginForm()" form-autofill-fix>
<div>
<input type="email" ng-model="email" ng-required />
<input type="password" ng-model="password" ng-required />
<button type="submit">Log In</button>
</div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment