2

Problem: I created an input field with type text, but when page loads it is auto filled with username saved (saved for this website login page)in browsers form data. i want to show it clean when page load.

<input type="text" class="form-control search-field" placeholder="Search Item" 
ng-model="vm.applyCategFoodSearch" autocomplete="off" 
name="txtFieldForSearchItems">

i am unable to find solution, autocomplete='off' was suggested by many other sources, but issue not fixed. if it can be handled using html,jquery,javascript,angularjs. it will be good. I also reset the values in controller

 vm.applyCategFoodSearch='';

timeout also tried but not working

      $timeout( function(){
         vm.applyCategFoodSearch='';
    }, 5000 );

if i set time out to 10seconds, it will work, but its not the solution. i am sending ajax call for food categories,when it returns, this timeout code will run with 10second delay.it will work. other than 10second delay.it will not work.

Faseeh Haris
  • 633
  • 1
  • 5
  • 22

3 Answers3

1

In the controller you may set it to empty string.

applyCategFoodSearch="";

basically it will be like this $scope.applyCategFoodSearch="" or this.applyCategFoodSearch="" , depends on whichever you prefer

brk
  • 43,022
  • 4
  • 37
  • 61
1

autocomplete='off' these days is ignore by major browsers. I suggest that you create a random string for each session and when you are outputting html you append the random String to name parameter value. For example , suppose the random String is "fjsdorf" , you can output this name="fjsdorf_txtFieldForSearchItems". When you get the data at the server , you can append the random String when you want to access the parameter values.

Dishonered
  • 6,544
  • 7
  • 23
  • 43
1

try this, hope this helps:

<input type="text" name="foo" autocomplete="off" />

or try with jquery on page load:

$('input#Password').val('');
Ajay Malhotra
  • 1,645
  • 2
  • 13
  • 16