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

Question

Question

Noob JavaScript Question for Modern Designer (nested field rules)

asked on May 30, 2024 Show version history

I need to hide rows in a table when 'dayNm' is 'Sat or 'Sun'. But if a single checkbox (or radio) is checked/selected, then show the hidden rows. 

I'm having a heck of a time using LFForm object to actually get the value from the checkbox field. 

Things I've tried:

  • LFForm.getFieldValues('showWeeknd').checked;
  • var isChecked = LFForm.getFieldValues('showWeeknd');
  • isChecked[0], isChecked[1], etc..

 

IF anyone has a tip on finding the row for the Sat and Sun rows, that would be helpful too, but right now I'm focused on just getting the value of the trigger field so I can tell if it is checked or not and then show or hide. 

Thanks in advance. I'm sure someone has already figured this out already :) 

0 0

Replies

replied on May 30, 2024 Show version history

I really think you'll be able to do what you are doing with Field Rules so much easier than Javascript - the field rules in the Modern Designer are so much more powerful than in the Classic Designer.

That said - here is some Javascript with a lot of detailed comments regarding how to work with LFForm.getFieldValues and values from a checkbox field.  This was tested in Version 11.0.2311.50556. 

//Let's assume we have a checkbox with variable
//of showWeeknd that has checkboxes for Saturday
//and Sunday.
LFForm.onFieldChange(function() {

  //Variable declaration.
  let isChecked = ''; 
  
  //This should return an object with details from the checkbox.
  //the console will show the following:
    //  no checks:         an object with a child object named value (with 0 elements)
    //  Saturday checked:  an object with a child object named value (with 1 elements)
    //  Sunday checked:    an object with a child object named value (with 1 elements)
    //  Both checked:      an object with a child object named value (with 2 elements)
  isChecked = LFForm.getFieldValues({variableName: "showWeeknd"});
  console.log('1: ');
  console.log(isChecked);
  
  //This should return an array of the values from the checkbox.
  //the console will show the following:
    //  no checks:         {empty string}
    //  Saturday checked:  Saturday
    //  Sunday checked:    Sunday
    //  Both checked:      Saturday, Sunday
  isChecked = LFForm.getFieldValues({variableName: "showWeeknd"}).value;
  console.log('2: ' + isChecked);
  
  //This should return the first value from the checkbox.
  //the console will show the following:
    //  no checks:         {undefined}
    //  Saturday checked:  Saturday
    //  Sunday checked:    Sunday
    //  Both checked:      Saturday
  isChecked = LFForm.getFieldValues({variableName: "showWeeknd"}).value[0];
  console.log('3: ' + isChecked);
  
  //This is the same as the second one, but will loop through 
  //each item in the array.
  //the console will show the following:
    //  no checks:         {does not run}
    //  Saturday checked:  Saturday
    //  Sunday checked:    Sunday
    //  Both checked:      Saturday
    //                     Sunday
  isChecked = LFForm.getFieldValues({variableName: "showWeeknd"}).value;
  isChecked.forEach(function(element) {
    console.log('4: ' + element);
  });
  
  //Put a break into the log.
  console.log('-----------------');
  
//End of LFForm.onFieldChange(function() {
}, {variableName: "showWeeknd"});

 

1 0
replied on May 30, 2024

Thanks Matthew, I have some pretty complex field rules already governing the columns of the table and hiding individual rows would cause MANY more field rules, so that's what led me to the javaScript. 

1 0
replied on May 30, 2024

Unfortunately you will probably have an even worse time trying to hide individual rows of a table because that is not supported in LFForm right now. You could use JS to update a hidden column of the table using whatever business logic you need so that your field rule is much simpler.

3 0
replied on May 31, 2024

Well I found the Easter Egg ha ha. Not sure when you snuck in nested conditions into field rules, but that did the trick. My field rules got WAY busier but I love the functionality. 

Exhibit A:

 

1 0
replied on May 31, 2024

Oh yeah, the nested conditions were such a big add to Field Rules in the Modern Designer.  I'm finding myself getting so frustrated with the limited Field Rules available in the Classic Designer.

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

Sign in to reply to this post.