Expand my Community achievements bar.

How to make table cells mandatory when visible

Avatar

Level 2

I have a form with two hidden subforms. Each subform contains a table with fields that need to be mandatory when visible.

The subforms are hidden or revealed based on a selection from a drop-down list.

I found the below script which works great for making a text field mandatory when visible, but, how do you apply this to cells in a table?

I can't figure it out.

if ("RMC-Fort Lupton-FIRE-DOT" == xfa.event.newText)

{

    Table.FL.presence = "visible";

    Table.FL.TextField1.mandatory ="error";

}

else

{

    Table.FL.presence = "hidden";

    Table.FL.TextField1.mandatory ="disabled";

}

if ("RMC-Ault-FIRE-DOT" == xfa.event.newText)

{

    Table.ALT.presence = "visible";

    Table.ALT.TextField2.mandatory ="error";

}

else

{

    Table.ALT.presence = "hidden";

    Table.ALT.TextField2.mandatory ="disabled";

}

Thanks in advance!

4 Replies

Avatar

Level 5

Hi

I applied this in a blank new form and it worked fine:

form1.page1.Table1.Row1.Cell1.mandatory = "error";

Are you getting any erros in the Javascript console?

Avatar

Level 2

Thanks for responding Diego,

I tried it and it works fine, but, what if the table has 27 rows and two mandatory cells in each row?

Is there someway to combine them into one line of script? To do them individually will require 54 lines of script just for one table, assuming one line of script for each mandatory cell. The form I creating will eventually have four hidden tables, each with a similar number of rows.

Avatar

Level 9

Hi,

You can use bit of scripting to count the no.of rows and according to that you can loop through them. But before that you need to check the table structure. Can you show the table structure?

Thanks,

Bibhu.

Avatar

Level 2

Hi Bibhu,

Thanks for responding.

Here is the table structure. Rows 1 through 25 are all the same. Each row has two cells with Radio Buttons named "AsFound" and "AsLeft." Both need to be mandatory when visible. If you need more information, let me know.

Hierarchy.png

Thanks!

Kurt