0

This seems like a trivial issue but for whatever reason I can't initialize any of my inputs to be blank/empty. Google Chrome is somehow setting the value to an older cached value.

Current view (even after emptying cache and doing a hard reload)

enter image description here

Empty View (this is what I'm trying to accomplish)

enter image description here

I've tried the following:

<form class="m-t" name="loginForm" id="loginForm" role="form" novalidate>
    <input type="email" class="form-control" name="email" ng-model="login.email" placeholder="Email Address" autocomplete="email" required>

    /* Also tried using ng-init */
    <input type="email" class="form-control" name="email" ng-model="login.email" ng-init="login.email=''" placeholder="Email Address" autocomplete="email" required>

I've also tried setting it to "" in the controller like so:

function LoginUserCtrl($scope, $http, $state, user) {

    $scope.loginForm.email = "";
    // console.log($scope);

    ...

});

What am I missing? Is this specific to Google Chrome?

Paul
  • 11,671
  • 32
  • 91
  • 143
  • I saw someone use a directive to solve this issue. I think I did something similar. Did you see this SO post? https://stackoverflow.com/questions/34441812/by-default-how-to-set-ng-model-value-to-an-empty-string – Paurian Jul 17 '19 at 16:15
  • Try adding `autocomplete="off"` to form. Chrome has been annoying lately at being too aggressive with their autofill – charlietfl Jul 17 '19 at 16:16
  • Paurian Unfortunately this no longer seems to work ... – Paul Jul 17 '19 at 17:02
  • charlietfl This doesn't work either...Google is making this really difficult – Paul Jul 17 '19 at 17:03

2 Answers2

0

What you are seeing is a result of Chrome's Autofill feature. Notice the blue background of the form field. That indicates it is an autofill value.

You mentioned that you emptied the cache, but in this case I don't think you opted to erase your autofill cache. Specifically you should look into the Addresses and more settings of Autofill.

ctaleck
  • 1,658
  • 11
  • 20
  • I want all clients who connect to this page to see an empty field, not just from my local machine. – Paul Jul 17 '19 at 17:05
  • If this is indeed what is happening, then I don't think you can control your client's machine because this is a browser-controlled feature. In your case, does clearing the Autofill fix the issue? – ctaleck Jul 18 '19 at 23:05
0

You are using form name to set its value empty which is not correct.

try this way in your controller to set empty value:-

function LoginUserCtrl($scope, $http, $state, user) {
    $scope.login.email = "";

    ...
});
Manish Balodia
  • 1,863
  • 2
  • 23
  • 37