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

Question

Question

Row Color in a Collection

asked on July 18, 2016 Show version history

I have a collection where people can attach rows of documents to a collection for approval.  If the documents are approved then they get saved into Laserfiche and if they are rejected then they get deleted via Workflow.  I am wanting each row in the collection to change color based on the selection from a radio button.  Thus in the image below if they pick "Approved" the background for that particular row in the collection turns green ( I can mess with the shade of green later) and if they pick "Rejected" it the background turns red.  

I have tried to use the code from the Answers post regarding line color but have been unsuccessful in getting it to work.  Has anyone been able to accomplish this with a collection and if so what is the trick with the javascript?

0 0

Answer

SELECTED ANSWER
replied on July 19, 2016

You can certainly do it with JavaScript. Not sure what you tried previously. Suppose you put a CSS class on your radio button ApprovalRB. Then the following code should work:

$(document).ready(function(){
  $('.cf-collection-block').on('click','.ApprovalRB input[type="radio"]',function(){
    switch($(this).val()){
      case "Approved":
        $(this).closest('div.form-q').css('background-color','green');
        break;
      case "Rejected":
        $(this).closest('div.form-q').css('background-color','red');
        break;
      default:
        $(this).closest('div.form-q').css('background-color','transparent');
        break;
    }
  });
});

A couple of notes here. First, it is important to use a delegated event handler in this case [ .on(event, selector, function) ] so that you handle events for any row in the collection that may be added after the page loads. Second, this doesn't override the default highlighting applied to the actively selected field, so it may look a little strange / partially-highlighted the moment you click the radio button. You could change that too if you wanted.

2 0
replied on January 29, 2018 Show version history

Hi Scott

Would you have a version of this that applies to the fields at time of form load, as well as when the buttons are changed?

 

 

0 0

Replies

replied on July 20, 2016

Sorry, I meant to post my code but I had an outage happen while typing that question and got sidetracked.  Your code worked GREAT!!!!  Thank you so much as you saved me a ton of time.  I was heading down that path but it would've taken me awhile to get there as I was working with ul and li instead of div.  Thanks again for the help

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

Sign in to reply to this post.