You are viewing limited content. For full access, please sign in.

Question

Question

Forms read only fields populated by browser

asked on July 16, 2018

Hello, 

 

I have a couple required read only fields on a form that I use for validation. 

The problem is, if a user has auto-complete of fields on their browser, it tricks the field into thinking there is a value there and allows the user to submit. Of course, the data isn't captured because it isn't actually IN the read only field. 

 

I am not sure if this makes sense...please let me know how I can clarify or if you have a solution. 

 

Thanks.

0 0

Answer

SELECTED ANSWER
replied on July 19, 2018

Just found an example on one of my forms doing the same. In this particular application, since the field is intended to be read-only, this may be the easiest way:

$('#q11 input').prop('readonly',true);
0 0

Replies

replied on July 19, 2018 Show version history

Not sure if every browser respects it, but this should turn off autocomplete:

$('.foo input').attr('autocomplete','off');

Or, if it truly doesn't add a value to the field, you could test for it on submit:

  $('.Submit').click(function(e) {
    if ($('.foo input').val() == '') {
      window.alert('no worky');
      e.preventDefault();
    }
  });

 

0 0
replied on July 19, 2018

Hi Scott! 

I am not sure what I am doing wrong but it is not working. 

$(document).ready(function () {
$('#q11 input').attr('autocomplete','off');
$("#q186 input").attr("type", "password");
$("#q187 input").attr("type", "password");
$("#q194 input").attr("type", "password");
$("#q195 input").attr("type", "password");
});

My others work fine to mask the input fields, but the autocomplete off isn't working. I am in Chrome. 

Any ideas? 

0 0
SELECTED ANSWER
replied on July 19, 2018

Just found an example on one of my forms doing the same. In this particular application, since the field is intended to be read-only, this may be the easiest way:

$('#q11 input').prop('readonly',true);
0 0
replied on July 19, 2018

You are an absolute lifesaver!!!!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.