Skip to content

Instantly share code, notes, and snippets.

@GonchuB
Created March 10, 2014 13:50
Show Gist options
  • Save GonchuB/9465255 to your computer and use it in GitHub Desktop.
Save GonchuB/9465255 to your computer and use it in GitHub Desktop.
Form autofill fix without jQuery
'use strict';
angular.module('freqshoApp')
.directive('formAutofillFix', function () {
return function (scope, elem, attrs) {
// Fixes Chrome bug: https://groups.google.com/forum/#!topic/angular/6NlucSskQjY
elem.prop('method', 'POST');
function triggerChangeHandlers(element) {
element.triggerHandler('input').triggerHandler('change').triggerHandler('keydown');
}
// Fix autofill issues where Angular doesn't know about autofilled inputs
if (attrs.ngSubmit) {
setTimeout(function () {
elem.unbind('submit').bind('submit', function (e) {
e.preventDefault();
triggerChangeHandlers(elem.find('input'));
triggerChangeHandlers(elem.find('textarea'));
triggerChangeHandlers(elem.find('select'));
scope.$apply(attrs.ngSubmit);
});
}, 0);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment