Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to determine if a table has no body rows?

_Bill_Bain_
Level 4
Level 4
Our form has a table where the user checks a box to include a product in a table by making the table row visible (otherwise the row is hidden). However, if none of the boxes are checked, I'd like to hide the table so that the header and footer rows aren't visible as well. Is there a way to determine if there are any body rows in a table, since that would tell me whether any product was selected? Does instanceManager only count body rows? Thanks in advance!
9 Replies
pguerett
Level 10
Level 10
Each subform has its own instanceManager so you can get a count of the rows subform if you wish.
_Bill_Bain_
Level 4
Level 4
So, if for example, the table name were "Table1" and the body rows were "Row1[*], I could use something like:



if(Table1.Row1.instanceManager.count == 0)

Table1.presence = "hidden";



Subforms and tables can be a bit confusing . . . . .
_Bill_Bain_
Level 4
Level 4
Nope. That didn't work. Even if the table has no body rows, the count reports as 1.
Ryan_Lunka
Level 5
Level 5
Are you sure the repating table row is set to have no Min Count? You could also try to alternative. I've had some problems using the object.instanceManager.method() format. For some reason it won't work for me sometimes. The way that is supposed to be FormCalc, but has always worked for me in JS (I never use FormCalc) is...



Table1._Row1.count == 0



Using the underscore notation is the same as adding .instanceManager and for whatever reason is more consistent in my experience. It's also a bit shorter.



Hope this helps!



Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com
pguerett
Level 10
Level 10
If there are no rows present then the objects don't exist and accessing the instanceManager is impossible. The _subformName allows access to instanceManager even though the rows do not exist. One looks at the layout dom and one looks at the tempalte dom.
_Bill_Bain_
Level 4
Level 4
I'm clearly not getting something here -- even with the suggested change, Table1._Row1.count still reports 1 even when all the body rows are set to "hidden". Help!
pguerett
Level 10
Level 10
Do you have a min count set?



Also if you want to send your form to livecycle8@gmail.com I can have a look.
Thomas_McConnac
Level 4
Level 4
Hidden only removes them from the layout, it doesn't mean they no longer exist.



You could count all of the body rows and then use an if statement to check if that row's presence is set to visible, then if it is set the table to visible.



pseudo code:

---------

table.presence = "hidden"



for (var i = 0; i < row.count; i++)



{



if row.all.item(i).presence == "visible"



{



table.presence = "visible"



}



}



---------



This will make the table visible if any of the rows are visible. And I would only use this if there is a reason you are setting the row to hidden, instead of making it so the count minimum is 0.



Hope this helps,



Tom
Not applicable
If the count is <= 1, then you could check to see if some required field is null. If it is, then the row must be blank and the table is empty.



I think. 🙂