check vibility of variable

r_gissarl_
Mega Expert

Hi,

I need to check a variable in a catalog client script onSubmit(). If the variable is visible, I need to check it. If it is not visible, the script does nothing.

So I need to access to the visibility of the variable, I thought about document.getElementById("IO:2bff02ec51ed21002b74916df91c253b").style.visibility or style.display.

But to get the status, I need to set it before... visibility or display returns nothing if I don't set it before (which is not what I need).

Any idea on how to get the visilibility (true / false) of a variable ?

Thanks.

1 ACCEPTED SOLUTION

ChrisRoyer
Kilo Guru

EDIT: I think the following function will be what you're looking for.



just call this in your client script and you should be good to go. I've only tested this in a few scenarios and directly on the catalog item, haven't looked at a submitted form yet or anything along those lines. I'll try and update if I end up doing any more work on this.



function isVisible(fieldName) {


  //This script does appear to return undefined if the variable name isn't present


  var field = fieldName;


  var id = g_form.resolveNameMap(field); //This will return IO:sys_id


  var clean = g_form._cleanupName(field); //this should return just the sys_id variable


  var nidot = gel('ni.' + id); //checkbox variables are hidden on this element.


  var ctrl = g_form.getControl(id); //not used in this script, but get's the prototypeJS elemnt


  var container = gel('container_' + clean); //getting the element for a container, one we actually don't have to crawl for parent nodes or anything along those lines


  var label = gel('label_' + id); //This should be all other field types. (testing was limited to single/multi line text, reference, and list collector) mileage may vary


  if (container) {


  return container.visible();


  }


  if (nidot) {


  return nidot.parentNode.visible();


  }


  if (label) {


  if (hasClassName(label, 'io_label_container')) {


  return label.visible();


  } else {


  return label.up(1).visible(); //same as label.parentNode.parentNode.visible(), just shorthand.


  }


  }


}


View solution in original post

12 REPLIES 12

Daniel Oderbolz
Kilo Sage

I have created an idea for this with the code we currently use. Basically, we use code from jQuery to determine if an element is visible. Then we call this function on the variable and if it not visible, we check if the parent is visible.

As I wrote in the idea, this should be handled by the g_form API.


If this answer was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel

Community Alums
Not applicable

I'm not sure when it became a feature, but g_form.isVisible(g_form.getGlideUIElement("your_field_name")) is now available and working.  I've submitted a request to add it to the documentation since it still isn't there.  I don't understand why, but the idea that Daniel submitted was even marked as "unlikely to implement." 

For catalog client script in Service Portal (mobile g_form), you can even access to the feature with a simple g_form.isVisible("your_variable_name");