How to turn off Visibility of top level fields only?

G24
Kilo Sage

In client script I wanted to turn off all fields until such time as they are necessary, as determined by the user selecting a particular Category value, so I write this function:

 

function makeAllFieldsNotVisible() {
    var allFields = g_form.getEditableFields();
    for (var i = 0; i < allFields.length; i++) {
        if (allFields[i] !== 'u_category') {
            g_form.setVisible(allFields[i], false);
        }
    }
}

 

I did this because I didn't want to have to individually list all 57 fields on my form.  Also, I wanted it to automatically take care of any fields which might be added in the future.
 
This works well for top level fields.  BUT... It also seems to make NOT VISIBLE those fields which are WITHIN variable sets.  So then, I can't just turn on the variable set top level item.  I need to turn on each and every field WITHIN the variable set also.
 
So my question is
1)  How can I make NOT VISIBLE the top level fields only, without messing with fields in variable sets?
   OR
2)  How can I determine at runtime, in client script, which fields came from variable sets?
2 REPLIES 2

Peter W1
Tera Contributor

Hi G24,

 

Have you looked at the item_option_new table? In my PDI it lists the variable along with the associated catalog item and what variable set it belongs to (if any). Maybe you could create an ajax call that gets called from your client script and goes to that table and checks the variables for that specific catalog item. Since you have 57 variables to check that is a lot of individual ajax calls so I would consider combining all the variables into an array and passing that as a parameter. On your callback function you would need to parse out whether each of those 57 variables should be shown or not, based on whether it belongs to a variable set.

 

Good luck!

jcmings
Mega Sage

I am wondering why you have 57 fields on your form. This sounds like the bigger issue to me. Can you share a bit more about what you're doing with this long form? Why are you using a client script rather than a UI Policy?