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

Question

Question

Read Only Checkbox Field Not Re-Populating After Saved as Draft

asked on October 3, 2018

We have a form that we are using the following JavaScript to make a checkbox field readonly:

$('.read-only input:checkbox').attr('disabled', true);

There is a field at the beginning of the form that is populated and then performs a lookup using the Lookup Rules. Then there is JavaScript that based on if one of the lookup fields is populated with the value 'Yes', it checks or unchecks a value in the read only field mentioned above.

$("Field127")/cjamge(function(DoWork){
  if(DoWork.currentTarget.value=="Yes")
{
  document.getElementById("Field85-0").checked=true;
}...

All of that works. But, when the form is saved as a draft and then re-opened, the checkbox value is gone.

Any ideas how to get the checkbox field to keep it's value?

1 0

Replies

replied on October 4, 2018

This behavior actually comes straight from HTML. Data from input elements with the disabled attribute are not sent to the server on a Submit (See the TIP in the middle of this page). Try using the read-only attribute instead.

2 0
replied on October 4, 2018 Show version history

We're running on Forms v10.3.1.635

Trying the code below (also trying .prop)
 

$('.read-only input:checkbox').attr('readonly', true);

I've verified in the debugger console that the element is flagged readonly, but in Forms I can still interact with the checkbox. Any advise?

 

readonly attr not working.jpg
0 0
replied on October 4, 2018 Show version history

So this may get a bit complicated because disabled values do not get saved, and read-only checkboxes don't work as expected.

What you want to do is detect when the form is going to be submitted or saved, then remove the disabled attribute right before that so it keeps the value.

Try adding this code to your form:

$(document).ready(function(){
  $('.Submit, button[value="__SaveDraft"]').click(function(){
    $('.read-only input:checkbox').removeAttr('disabled');
  });
});

The idea here is that any time a user clicks the Submit button on the form, or the "Save" button in the Save as draft modal dialog, it will remove the disabled attribute right before it actually submits allowing the value to be saved.

If that still doesn't work, try adding the .change() event after you check the box to make sure the value is actually sticking.

The thing to watch out for is if they click Submit but some of the fields don't validate because then you might end up with the field being enabled/editable, but that can be dealt with as well and this should point you in the right direction.

2 0
replied on October 4, 2018

Excellent! Due to the particulars of this Form, I don't need the values when I submit, only when I save a draft. I replaced .Submit, button[value="__SaveDraft"] with .draft-btn and things are working as needed! 
 

Thanks so much for your help.

0 0
replied on October 4, 2018 Show version history

Be careful with that, the reason I used button[value="__SaveDraft"] instead of .draft-btn is that the former targets the actual Save button.

If you target the "Save as draft" button, users could click Cancel or Close from the modal and then your field is exposed/editable.

0 0
replied on May 15, 2019

Hi Jason,

Turns out I do actually need the values on submit. I have tried your recommended script with 

$('.Submit, button[value="__SaveDraft"]').click(function(){

And it is not saving the values in the check boxes when I save draft. Any ideas?

 

0 0
replied on May 15, 2019

How are you checking/unchecking the boxes?

0 0
replied on May 16, 2019

A lookup Populates some hidden fields, then Jscript checks boxes based on those hidden field values. 

I got things to work if I make a separate function for .Submit and .draft-btn, but was not able to get it working with one function containing both 

$('.Submit, .draft-btn').click(function(){

Nor can I get it to function using button[value="__SaveDraft"], whether that is contained in it's own function or together with .Submit.

The end result is I have most of the functionality they need, saving the correct values on Save Draft and Submit, but still have the possibility of someone cancelling a Save Draft and making what should be read only fields available to edit.

0 0
replied on May 16, 2019

Which version of Forms are you running? My suggestion would be to right-click and inspect the actual save button on the pop up.

This is the button that you're targeting and in the version I'm running it has the value used in the JQuery selector.

Testing in the browser console will also confirm whether or not the selectors are functioning.

0 0
replied on May 16, 2019

Forms 10.3.1.635

Here is the inspect:

0 0
replied on May 16, 2019

Interesting. It looks like the selector is fine, so something else must be going wrong.

0 0
replied on October 3, 2018

Which version are you using? I ran into a problem with drafts not saving read-only data in a previous version, which was fixed in an update.

Alternatively, you can try triggering the .change() event on the field after you set the value to see if that may be the reason it isn't preserving the value.

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

Sign in to reply to this post.