Collapse the form section

snowlearner
Kilo Expert

How can we collapse the form section on load.

13 REPLIES 13

I tried it but it only toggles i.e. sometimes it would display or sometimes it would hide the sections. I wanted a function which can always make the section as of collapsed when the form loads. I am wondering if that is possible .


snowlearner
Kilo Expert

Hi snowlearner,



Here is an implementation of what I suggested earlier, with a couple of minor tweaks to check for the sections not being collapse already. This works only on Fuji (because of the shortcut I used to get the sections):



function onLoad() {


      var section,sections = g_form.getSections();


      for (var i=0; i<sections.length; i++) {


              section = sections[i];


              if(! ((' ' + section.className + ' ').indexOf(' state-closed ') > -1) )


                      hideReveal(section.id.substr('section-'.length));


      }


}



This is just a small step beyond what was suggested earlier. With a little experimentation and research in your dev console, you should be able to find out how getSections, g_tabs2Sections, and hideReveal work. If you need this on Eureka and earlier, you should be able to extrapolate out what is here and figure out how to do it without the getSections function.


😮   Is line 2 a way to declare a variable and make it equal   to something on the same line!?


Hi Robert,



No, it's declaring 2 variables (section and sections) while setting section equal to undefined and sections equal to the array returned by g_form.getSections();



It's really just so I don't re-declare the section variable each time through the loop.