Highlighted

How to determine if a table has no body rows?

Avatar

Avatar

_Bill_Bain_

Avatar

_Bill_Bain_

_Bill_Bain_

09-12-2008

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!

Replies

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

09-12-2008

Each subform has its own instanceManager so you can get a count of the rows subform if you wish.
Highlighted

Avatar

Avatar

_Bill_Bain_

Avatar

_Bill_Bain_

_Bill_Bain_

10-12-2008

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 . . . . .
Highlighted

Avatar

Avatar

_Bill_Bain_

Avatar

_Bill_Bain_

_Bill_Bain_

10-12-2008

Nope. That didn't work. Even if the table has no body rows, the count reports as 1.
Highlighted

Avatar

Avatar

Ryan_Lunka

Avatar

Ryan_Lunka

Ryan_Lunka

11-12-2008

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
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

11-12-2008

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.
Highlighted

Avatar

Avatar

_Bill_Bain_

Avatar

_Bill_Bain_

_Bill_Bain_

11-12-2008

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!
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

11-12-2008

Do you have a min count set?



Also if you want to send your form to livecycle8@gmail.com I can have a look.
Highlighted

Avatar

Avatar

Thomas_McConnac

Avatar

Thomas_McConnac

Thomas_McConnac

11-12-2008

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
Highlighted

Avatar

11-12-2008

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. 🙂