Skip to content

Disable autocomplete automatically for all forms in AngularJS

When developing CRMs autocomplete is often useless or altogether detrimental. If you end up having a case where no element will ever need autocomplete, one of the fastest ways to achieve this is hooking an AngularJS directive to the form element:

(function() {
  'use strict';

    .directive('form', htmlFormDirective);

  function htmlFormDirective() {
    return {
      restrict: 'E',
      compile: function(elem, attrs) {
        elem[0].setAttribute('autocomplete', 'off');