client script, show/hide section

Ak_12
Tera Contributor

On my customtable form i have field subcategory (choice), choices are desktop, laptop, tab, printers, mobile. and i have created sections for all that choices separately. so if i select desktop only desktop section should be visible, like this for every choice  

8 REPLIES 8

Anubhav24
Mega Sage
Mega Sage

Hi Avi,

Based on the value selected which can be obtained in the onchange client script using g_form.getValue(<fieldname>) , you can then hide or show the sections using : setSectionDisplay(String sectionName, Boolean display) . Also you can use the function getSectionNames() to get the section names on the form.

 

Ak_12
Tera Contributor

Does this script works? i have tried but i got g_form.getsection error, is there any changes i have to make here

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

var desktopSection = g_form.getSection('desktop');
var laptopSection = g_form.getSection('laptop');
var tabSection = g_form.getSection('tab');
var mobileSection = g_form.getSection('mobile');
var printerSection = g_form.getSection('printer');

switch (newValue) {
case 'desktop':
desktopSection.show();
laptopSection.hide();
tabSection.hide();
mobileSection.hide();
printerSection.hide();
break;
case 'laptop':
desktopSection.hide();
laptopSection.show();
tabSection.hide();
mobileSection.hide();
printerSection.hide();
break;
case 'tab':
desktopSection.hide();
laptopSection.hide();
tabSection.show();
mobileSection.hide();
printerSection.hide();
break;
case 'mobile':
desktopSection.hide();
laptopSection.hide();
tabSection.hide();
mobileSection.show();
printerSection.hide();
break;
case 'printer':
desktopSection.hide();
laptopSection.hide();
tabSection.hide();
mobileSection.hide();
printerSection.show();
break;
}
}

Hi ,

Is this function working for you  g_form.getSection('desktop'); 

To get all the sections available on a form whether visible or not we can use g_form.getSectionNames() and it returns an array you can then loop through array and make your sections visible or hide them and as mentioned above to hide sections altogether you need to use g_form.setSectionDisplay(String section Name, Boolean display).

Ak_12
Tera Contributor

this script is for when category is hardware, subcategory should visible. and choosing subcategory following sections should visible. below i attached ss of form

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

var categoryValue = g_form.getValue('category');
var subcategoryValue = g_form.getValue('subcategory');

var isHardware = categoryValue == 'hardware';

g_form.setDisplay('subcategory', isHardware);

if (isHardware) {
var desktopValue = subcategoryValue == 'desktop';
var laptopValue = subcategoryValue == 'laptop';
var tabValue = subcategoryValue == 'tab';
var mobileValue = subcategoryValue == 'mobile';
var printerValue = subcategoryValue == 'printer';

g_form.setDisplay('desktop', desktopValue);
g_form.setDisplay('laptop', laptopValue);
g_form.setDisplay('tab', tabValue);
g_form.setDisplay('mobile', mobileValue);
g_form.setDisplay('printer', printerValue);
}
}