← All articles

Nintex Forms - Accordion Like Functionality

Accordion functionality in forms is a nice feature.  It makes for slicker usage of the form, since not everything needs to be displayed on a huge form, which can overwhelm a person filling in that form.

I recently had a question on how to get this type of functionality into a Nintex Form.  A big shout out goes to Daniel Kinal (@dktpm on Twitter) who came up with the idea behind what I'm posting here.  Daniel is a Nintex Forms guru.

To get the accordion style functionality, there is a little bit of work to be done, but if you want this type of functionality in your form, it's well worth it.

VIDEO

What Is Required for this Form Design?

This form will use a number of features that are part of Nintex Forms.  You will need some rules and also some JavaScript.  I go into some details of this in the video above, but it comes down to that there's no Toggle button yet in Nintex Forms.  The only way to simulate toggling is to use a check box.  But when it comes to an accordion, we want buttons, not check boxes.  For each section of the accordion, you will need to have a Yes/No control.  Then, you need to hide these Yes/No controls using a rule.  The rule I put in the form simply checks that if this form is a New/Edit/Display or Live form, I want to hide the Yes/No controls.

[Image unavailable: Rules.png]

Next, we have a rule for each section.  Each section, being a Panel (groups a bunch of controls).  The rules for each section is based on the value of the Yes/No control that corresponds to it and hides that section if the yes/no is not checked.

[Image unavailable: CheckBoxes.png]

Finally, we have a button for each section and the buttons are configured to be JavaScript button, each calling their own JavaScript function.

[Image unavailable: FormClosesSections.png]

After clicking on a button

[Image unavailable: FormWithOpenSection.png]

All the JavaScript is doing, is finding the appropriate Yes/No control and calling the click() function on it.  Simulating a button click or checking/unchecking the box.  This will cause the rules to re-evaluate and will then hide/show the appropriate section.

What does the Javascript look like?

var onlyOneSectionVisible = true;
var currentVisibleSection = -1;

NWF$(document).ready(function()
{
});

function fnShowSection(iSection)
{
  if(onlyOneSectionVisible == true)
  {
      if(currentVisibleSection != iSection)
      {
        var controlClass = NWF$('.cssCheckBoxSection' + iSection);
        var myInput = controlClass.find('input');
        myInput.click();
        if(currentVisibleSection != -1)
        {
          controlClass = NWF$('.cssCheckBoxSection' + currentVisibleSection);
          myInput = controlClass.find('input');
          myInput.click();
        }
      }
  }
  else
  {
    var controlClass = NWF$('.cssCheckBoxSection' + iSection);
    var myInput = controlClass.find('input');
    myInput.click();
  }

  currentVisibleSection = iSection;
}

function fnSectionOneClick()
{
  fnShowSection(1);
}

function fnSectionTwoClick()
{
  fnShowSection(2);
}

function fnSectionThreeClick()
{
  fnShowSection(3);
}

function fnSectionFourClick()
{
  fnShowSection(4);
}

function fnPreviousPage()
{
  if(currentVisibleSection == 1)
    return;
  if(currentVisibleSection == -1)
    fnShowSection(1);
  else
    fnShowSection(currentVisibleSection-1);
}

function fnNextPage()
{
  if(currentVisibleSection == 4)
    return;
  if(currentVisibleSection == -1)
    fnShowSection(1);
  else
    fnShowSection(currentVisibleSection+1);
}

Important Information

In the JavaScript, there is a variable at the very top that is called onlyOneSectionVisible and it's set to true.  This means that as you click on one of the other sections, it will close the previous one and open the new one.

If you want to allow for multiple sections to be open at one time, set that variable to false.

Downloads

Nintex Forms 2013

Download the 2013 Form - Download (unzip) and import it into the Form Designer Page (UPDATED - added Previous and Next Buttons)

Download the 2010 Form - Download (unzip) and import it into the Nintex Forms 2010 Designer Page

Download the 2010 Form (supports multiple open sections) - Download (unzip) and import it into the Nintex Forms 2010 Designer Page