1

I accidentally copy and pasted something wrong just to discover it worked. That said, I am by no means an HTML expert so I don't know what the consequences of my code are, like what will break if I try to select the element's innerHTML or value. Anyway, here's my strategy:

<form name="mainForm" id="mainForm" class="mainForm">
    Email:<input type="email" name="emailBox" id="emailBox" class="userInput" placeholder="Enter email address" form autocomplete="off">

the "form autocomplete="off" at the end seems to break the autocomplete, but I'm not sure what else will be messed up. Let me know if it works for you please! Or if you can see the bugs this strategy is likely to cause...thanks!

Starlord
  • 11
  • 4
  • Incidentally, there is a [`form` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form) for `` elements. But its value "must be an id of a
    element in the same document".
    – showdev Feb 17 '16 at 00:01
  • Holy crap @showdev that's what I'm looking for!!!! First off, thanks. Secondly, how does this fix the autocomplete issue? Basically, I am making a form that needs to be different every time it is submitted and can NEVER recall info that has already been submitted. The main issue was that, even if it didn't complete the rest of the form, it would bring up options that have been submitted in the past. I don't have the problem on Internet Exploder, only Chrome. Haven't tested on firefox. So, any idea why this makes it so Chrome autocomplete doesn't work? All other solutions I find involve JS. – Starlord Feb 17 '16 at 20:57
  • Apparently the problem was that autofill was populating data, not autocomplete, when autocomplete="off". That's what I get for using a real email to test X| – Starlord Feb 19 '16 at 00:58

2 Answers2

0

Dear, you don't need to put that autocomplete in front of each and every input control until you wish to exclude some input controls out of validation. Just put in form tag and you'll get your job done.

  1. autocomplete="off" in form tag disables autocomplete for each and every control inside form tag
  2. If you wish to do it for some fields only then you put autocomplete="off" in that input control and remove this autocomplete="off" from form tag.
  3. And if you're using it with individual form control not for all form tag then you don't have to put form autocomplete="off". Remove that form tag from front of autocomplete="off" as you did above in your code.
  4. Correction of your code is given below:

    <form name="mainForm" id="mainForm" class="mainForm" autocomplete="off">
    Email:<input type="email" name="emailBox" id="emailBox" class="userInput" placeholder="Enter email address">
    </form>
    
  5. And always close the form tag.

And you are ambiguous still what you want to do or say. I can't understand. Whatever I understood I corrected it as above.

Cheers :)

Amulya Kashyap
  • 2,061
  • 11
  • 23
  • I know it's a bit ambiguous, it's just a problem which keeps coming up. I originally had "autocomplete="off" in the form tag but in Chrome it still kept autocompleting. I then tried putting it in both form and input tags at the same time, then just the input tags. Apparently Chrome doesn't like to honor the autocomplete="off", at least according to my research (notably here http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off/22957859#22957859). I will try the autocomplete="off" again in the form, maybe the internet just didn't like me. – Starlord Feb 17 '16 at 20:35
  • Also, my question is honestly this: will me putting "form autocomplete="off"" at the end of an input tag affect that input's functionality? – Starlord Feb 17 '16 at 20:38
  • Refer to point no. 2 and 3 of my answer you'll get the solution – Amulya Kashyap Feb 18 '16 at 03:46
  • Apparently you can stop chrome from autocompleting but not autofilling things into fields it recognizes, which meant me testing it with an address i had saved made it look like it was autocompleting but was actually using autofill, google's tool that lets you save data. Interesting that I found a way to break autofill as well. Thanks! – Starlord Feb 19 '16 at 00:56
0

After much searching, I have created the solution below for the navigated was not respecting the "autocomplete = off".

When you load the page, check which elements are as "autocomplete = off" and create an attribute "default-readonly" for those who are already as "readonly" and for those who do not have the attribute "readonly" add it to leave non-editable field. After 300 milliseconds (you can use a little more), the script runs the elements again and remove the "readonly" of the elements that did not have this attribute. This allows the field with "readonly" the navigated not fill out the field. After all the screen and the browser execute their actions, it is taken from the "readonly" fields that should not have.

$(document).ready(function () {
 $('[autocomplete="off"]').each(function (index, item) {
  var readonly = $(this).attr("readonly");
  if (typeof readonly !== "undefined") {
   if (readonly) {
    $(this).attr("default-readonly", "");
   } else {
    $(this).prop('readonly', true);
   }
  } else {
   $(this).prop('readonly', true);
  }
 });

 setTimeout(function () {
  $('[autocomplete="off"]').each(function (index, item) {
   var readonly = $(this).attr("readonly");
   var defaultReadonly = $(this).attr("default-readonly");
   if (typeof readonly !== "undefined") {
    if (typeof defaultReadonly === "undefined") {
     $(this).prop('readonly', false);
    }
   }
  });
 }, 300);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form method="POST">
  <input type="text" name="telefone" autocomplete="off"/>
  <input type="password" name="pwd" autocomplete="off"/>
</form>

I hope this helps :)