Order of g_form.getSections vs. .g_form.getSectionNames

Brian Whyte
Kilo Guru

Seems like index 0 of the array returned by g_form.getSectionNames() is not the same of index 0 of the array returned by g_form.getSections().  I can't speak on the rest of the order, but this seems odd to me if we were wanting to evaluate the name to make a decision on what to do with the section.

 

I was trying to dynamically iterate these arrays and if the section name was "billing_fields", then hide the section with that same index.  What ended up happening is it was hiding the wrong section because the indexes didn't seem to align. It seems like index 0 of g_form.getSections() is the main part of the form.

 

Is this by design, if so, can we assume it's always off by one?  If it is (big questioning eyes).

1 REPLY 1

Amit Gujarathi
Giga Sage
Giga Sage

HI @Brian Whyte ,
I trust you are doing great.
g_form.getSectionNames() and g_form.getSections() may not align in index order because they return different types of data: section names and section objects, respectively. The first element in g_form.getSections() often represents the main form section, not a named section. To hide a specific section like "billing_fields", iterate through the sections using g_form.getSections() and compare names to find the correct section. Don't rely on matching indexes as this can lead to errors. Here's a simplified code example:

var sections = g_form.getSections();
for (var i = 0; i < sections.length; i++) {
    if (sections[i].name === "billing_fields") {
        g_form.setSectionDisplay(sections[i].name, false); // Hide the section
        break;
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi