Calculate the number of form controls


Badge +5

Hi,

I have a requirement to count the number of "unhidden" controls in a form. Take the example below:

184353_pastedImage_0.png

A choice control hides 1 or 2 calculated value controls. I need to display a total for the number of calculated values being displayed. For example:

When one calculated value control is displayed the count should return "1":

184354_pastedImage_3.png

When two calculated value controls are displayed the count should return "2":

184356_pastedImage_5.png

Is there some kind of JS sorcery that can identify whether a control is hidden or displayed and provide a count? I have attached an export of the form shown in these examples.


4 replies

Badge +11

Hi,

wouldn't evaluating your dropdown being easier than counting the hidden/unhidden controls?

You have 3 controls shown max. and the dropdown either hides one or two columns. Which means depending on the value of your dropdown there are either 1 or 2 controls shown.This probably won't even require javascript as you should be able to implement this with calculated values and formulas.

Please let us know, if this is not an option for you and why it isn't.

Regards

Philipp

Badge +5

Hi Philipp,

Thanks for responding. That's a good question and an interesting approach.

The example I've provided above is a simplified version of the solution I'm developing. In my actual solution I have a range of 21 calculated value controls that are displayed based on quite a number of formatting rules.

Mitch

Badge +11

I see. I would start by inspecting the DOM at this point. Open up your form in preview mode and run your browsers developer tools. Try to find your hidden/unhidden controls and see how they are hidden. There should be some flag/property/inline-styling that decides whether your controls are hidden or visible.

Afterwards you need to create some Javascript function to loop through all your conditional hidden controls and count the number of controls that are not hidden.

Regards

Philipp

Badge +5

Another great approach, thanks Philipp. When I return to this task I will give that a try and feedback with any results.

Reply