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

Question

Question

Forms - JavaScript color selection is not being kept when saved to repository

asked on May 13, 2024

We have a LF Forms process that uses a Java script to provide visually a positive or negative color response.

This function displays on multiple rows based on a primary field DB lookup to populate all of the subsidiary response fields

If the response is Authorized this will be displayed in green.

If the response is Not Authorized this will be displayed in Red.

This is working perfectly until we get to the Save to Repository aspect and all colors are no longer visible in the saved PDF.

Here is the script being used:

$(document).ready(function(){
colorObjectives();
});
function colorObjectives(){
$('.Authorized select').each(function() {
  
    if ($(this).val() == 'Authorized'){
      $(this).css('color', 'green', '!important');
    }
    else {$(this).css('color', 'red', '!important');}
  });  
  }

Any assistance would be appreciated.
 

0 0

Answer

SELECTED ANSWER
replied on May 13, 2024 Show version history

This is because your code is targeting "select" elements (i.e. dropdown fields) but when saving to the repository (and for read-only user tasks) most fields are converted to read-only non-field HTML elements, the only exception is checkboxes and radio buttons which are only disabled.

Try updating your selector to also target the read-only versions.

$('.Authorized select, .Authorized div.ro')

Another option would be to target the first child of the cf-field container, which should hold the target element regardless of whether it is editable or read-only.

$('.Authorized .cf-field > :first-child')

 

1 0
replied on May 13, 2024

Great, that would make sense.
I will try this for sure and provide a confirmation if this has resolved the issue.

Thank you.

0 0

Replies

replied on May 14, 2024

All good now.
I had to update the if ($(this).val() == 'Authorized') to if ($(this).text() == 'Authorized')
Thank you for your help with this!
 

1 0
replied on May 14, 2024

This seems to have partially worked with the following $('.Authorized select, .Authorized div.ro') syntax.
All of the Authorized classes change in the form view as expected.
When we look at the PDF printout, they are all set to red instead of being set by the statement value.

I am in process of trying the other $('.Authorized .cf-field > :first-child') syntax to see if this will apply the correct color within the PDF the way as it does within the form view.

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

Sign in to reply to this post.