AngularJS - using a form and auto-completion

前端 未结 2 695
萌比男神i
萌比男神i 2021-01-06 08:23

I have the following code in a partial page used for login...

2条回答
  •  半阙折子戏
    2021-01-06 09:03

    Here is an alternative solution that is semantically sound AngularJS: http://victorblog.com/2014/01/12/fixing-autocomplete-autofill-on-angularjs-form-submit/

    myApp.directive('formAutofillFix', function() {
      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);
        }
      };
    });
    

    Then you attach the directive to your form:

    
      

提交回复
热议问题