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

Question

Question

How to dynamically make table cell read-only based on value of different cell from same row?

asked on July 22, 2021 Show version history

I am creating a dynamic table for users to enter entries.

The table consists of several columns but I have reduced it to only 2 columns for this post.

Part of the requirements for the table is to toggle the first column field to read-only based on what value (lets say the value '2') gets selected from the second column dropdown.

For clarification, the screenshots provided mimic the behavior that I seek.

Picture with red circle should show the circled field as read only.

Is this possible?

Thank you

ans.JPG
ans2.JPG
ans3.JPG
ans.JPG (12.75 KB)
ans2.JPG (12.19 KB)
ans3.JPG (16.77 KB)
0 0

Answer

SELECTED ANSWER
replied on July 22, 2021 Show version history

Something like this should work for you. I have not tested it but I feel confident it should point you in the correct direction.

You would need to set the classes up. I hope I named them in a way you understand what goes with what.

You would call the function on load if the dropdown(select) field has it's data when loaded. You may also need to call it when you add a new row on the table.

The comparison for the if may not need the quotes around the 1

 

$(document).ready(function(){
  
  function setTableFieldReadOnly(){

  
    
    /* loop through the table */ 
    $('.theTableClass tbody tr').each( function() {
      /* set default values */
      var currSelectClasseValue = $(this).find('.theSelectClass select').val();
      var currOtherFieldClass = $(this).find('.theOtherFieldClass input');
      
      if (currSelectClasseValue=='1'){
        currOtherFieldClass.attr('readonly', true);        
      }
      else{
        currOtherFieldClass.removeAttr('readonly');        
      };
    }); /* END: table loop */
    
  }; /*END: function setTableFieldReadOnly() */ 
  
  /* when the select value changes */ 	
  $('.theSelectClass select').change(function(){     
    setTableFieldReadOnly();
  });  

});  //close document.ready

 

1 0
replied on July 29, 2021

Hey Genny,

Sorry for the delayed response, but this really helped me so much and sent me in the right direction.

Thanks!

1 0
replied on July 29, 2021

I'm glad it helped you :)

0 0
replied on November 7, 2023

Hi Genny I have similar issue.
Can you please have a look at it? Thanks.

https://answers.laserfiche.com/questions/213110/Make-2-fields-read-only-depending-on-dropdown-selection#213122

 

1 0

Replies

replied on July 22, 2021

We are still waiting on the options Read/Write in the field rules area, so right now you can only Show or Hide. What you could do is have a read-only field that always equals the write field, using a calculation.

Then show the read field and hide the write field.

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

Sign in to reply to this post.