Expand my Community achievements bar.

Changing column width based on checkbox

Avatar

Former Community Member

Hello!

I'm trying to remove a column based on whether or not a checkbox is selected.  I can't seem to select an entire column, only a row, and I can't make cells "hidden", so I've decided to try to reduce the width if I need it hidden.  My script under the change event is:

if($=="1")then

Table1.Row1.Cell10.w="0.4898in"

else

Table1.Row1.Cell10.w="0.001in"

endif

My initial setting for the cell width is 0.001 as the checkbox is "0"

Seems a little hokey and there must be a better way.  Even the above is not working at all.

Note I'm also only changing the size of one cell as doing so manually has proven to adjust the entire column.  Should I continue with this assumption when using a script?

Suggestions??

Thanks!

Joanne

4 Replies

Avatar

Level 10

Hi Joanne,

Have a look at this example here: http://assure.ly/gk8Q7a.

If you have a look at Table 5 in LC Designer, you will see that I have two columns at the end:

  1. A column with buttons to move rows up and down.
  2. A column with a button to delete the row.

If you look at the script in the click event of the Edit button, you will see that I have a loop that works its way through all the instances of Row1 and show/hides the appropriate cell in each row.

Hope that helps,

Niall

Avatar

Former Community Member

Thanks Niall ... though I've modified your response to FormCalc

It's begun to work though there appears to be a slight glitch.  Only the column cell for Row 1 is showing up.  It would seem that it isn't correctly counting/adding all rows.  Also, when I unselect the checkbox, it isn't re-hiding the column.

My script:

var vRows = Table1._Row1.count

if($=="1")then

var i=0; i<vRows; i++

Table1.Row1[" + i + "].Cell10.presence = "visible"

Table1.Row1[" + i + "].Cell11.presence = "visible"

Table1.Row1[" + i + "].Cell10.relevant = "+print"

Table1.Row1[" + i + "].Cell11.relevant = "+print"

else

var i=0; i<vRows; i++

Table1.Row1[" + i + "].Cell10.presence = "hidden"

Table1.Row1[" + i + "].Cell11.presence = "hidden"

endif

Joanne

Avatar

Level 10

Hi Joanne,

I would not have been inclined to change it to FormCalc. Why not leave it as JavaScript?

The syntax is not correct for FormCalc:

  1. I am not sure if the shorthand for instanceManager (_) works in FormCalc.
  2. You have not actually set up a for loop within the if statements. Check out Stefan Cameron's explanation of the FormCalc syntax for the for expression: http://forms.stefcameron.com/category/formcalc/page/2/

I think that this would be closer to working for FormCalc, however I have not tested.

var vRows = Table1.instanceManager.Row1.count - 1

if ($=="1") then

     for i=0 upto vRows do

          Table1.Row1[i].Cell10.presence = "visible"

          Table1.Row1[i].Cell11.presence = "visible"

          Table1.Row1[i].Cell10.relevant = "+print"

          Table1.Row1[i].Cell11.relevant = "+print"

     endfor

else

     for i=0 upto vRows do

          Table1.Row1[i].Cell10.presence = "hidden"

          Table1.Row1[i].Cell11.presence = "hidden"

     endfor

endif

I would recommend changing the language to JavaScript and following the previous example.

Niall

Avatar

Level 10

Okay, engage brain Niall

This should be much more straightforward in FormCalc without a for loop.

Try this in FormCalc:

if ($=="1") then

          Table1.Row1[*].Cell10.presence = "visible"

          Table1.Row1[*].Cell11.presence = "visible"

          Table1.Row1[*].Cell10.relevant = "+print"

          Table1.Row1[*].Cell11.relevant = "+print"

else

          Table1.Row1[*].Cell10.presence = "hidden"

          Table1.Row1[*].Cell11.presence = "hidden"

endif

The * wildcard should apply the changes in properties to all of the instances of Row1. See this example: http://assure.ly/kUP02y.

Hope that helps,

Niall