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

Question

Question

Pre-fill fields and make them read-only on the form

asked on December 8, 2021

I have a form where I pre-fill a few fields from a URL.  I would like these fields to be read-only for the form submitter.  But if I make the fields on the form read-only, my URL is not able to populate them.  Is there any way around this?

For example:  Pre-fill the Last Name field and make it read-only so they don't give me a variation on the spelling that is not in my database.

0 0

Answer

SELECTED ANSWER
replied on December 9, 2021

If you set the fields to Read only using JS instead of the field's Read Only checkbox, then the field will still accept the the URL input.

I add an ROClass to the fields I want to be Readonly and then use JS such as this to set them to readonly. The example code before is for Single Line, Drop Downs and Checkbox fields. 

 

$(document).ready(function () {
     $('.ROClass input').attr('readonly', true);
     $('.ROClass select').attr('readonly', true);
     $('.ROClass input:checkbox').attr('disabled', true);
});

2 0
replied on December 9, 2021
2 0

Replies

replied on December 8, 2021

Just to clarify your scenario, is there a reason you need to do it through the URL? If the information is coming from a database anyway, you could do lookups that are read only.

Something worth noting is that someone could always change, break, or even share the URL so I usually try to limit URL parameters to the bare minimum, like a database record ID and pull the rest in a lookup whenever possible.

3 0
replied on December 9, 2021 Show version history

$(document).ready( function() {

  $('#q25 input').prop("readOnly", true).prop("tabindex", -1);

});

tabindex = -1 takes the field out of the tab sequence

1 0
replied on December 9, 2021

That tabindex is new to me James. Thanks

0 0
replied on December 9, 2021

My favorite is 
  $('input[readOnly]').prop("tabindex", -1);
for forms with a lot of reference information

1 0
replied on December 14, 2021

This is great.  I will check out all of the suggestions.  Thank you very much.

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

Sign in to reply to this post.