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

Learn more

View all

Sign in to view all badges

SOLVED

Unable to hide subform in table cell dynamically

Siva407
Level 1
Level 1

Dear Friends,

i have a requirement where i need to make a subform in table row(cell) visible/invisible dynamically.

My Code:

data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA[0].#subform[1].#subform[2]::initialize - (JavaScript, client)
var length = xfa.resolveNodes("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA").length;
//var fields = xfa.form.subform.table.row.all;
xfa.host.messageBox("Hi");
for (var i=0; i<=length; i++ )
{
xfa.host.messageBox("Hi");
if ( xfa.resolveNode("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA["+ i +"].#subform[1].#subform[2].TextField1").rawValue == "X"){
this.presence = "hidden";
}else{
this.presence = "visible";
}
}

Problem 1. if the subform is hidden first row, it is hidden in all rows of table, where conditionally it should get visible/invisible.

               2. xfa.host.messageBox("Hi"); is not working, i have tried these as well none of the below is working for debugging purpose:

                    data.#pageSet[0].Page1.CurrentPage::initialize - (JavaScript, client)
                    xfa.host.messageBox("welcome","Error",3,0);
                   $host.messageBox("Welcome");
                   xfa.host.messageBox("Test");
                   app.alert("click");

 

 

1 Accepted Solution
radzmar
Correct answer by
Level 10
Level 10

Well, you can simply use this JavaScript in the calculate event of SpouseSF.

 

this.presence = Textfield1.rawValue == "X" ? "visible" : "hidden";

 

View solution in original post

9 Replies
radzmar
Level 10
Level 10

Well, I can't say what's wrong, without knowing the hierachy of you form. But I can already see some problems in your script.

 

1. DON'T name variables or form objects (subforms, fields …) after scripting properties or default form elements! That's a no go and can cause very strange effects! So you better use other names than "data" or "length".


2. This script will either return 0 or 1. It depends on, if the an element DATA below GT_TABLE below the fourth subform below the third subform below the first subform under the element data exists or nor. I think not, aand that would be, why you don't see the "Hi" message. 

// bad variable name "length", bad element name "data"! resolveNodes() will return 0 or 1 using this SOM expression.
var length = xfa.resolveNodes("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA").length;

 

 

Siva407
Level 1
Level 1
Dear radzmar,Please check my post i have provided herachy as well
Siva407
Level 1
Level 1

Hi Radsmar,

 

I am attaching you screenshot for better understanding:Code_snippet.JPG

Scenario is like this a column in table has multiple subforms, so for each record the particular subform should be visible if it has data.

otherwise it should be invisble.

Note: i have renamed subforms names and made necessary code changes as well for better understanding.

 

Revised Code:

 data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA[0].FamilySF.SpouseSF::initialize - (JavaScript, client)var len = xfa.resolveNodes("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA").length;
//var fields = xfa.form.subform.table.row.all;xfa.host.messageBox("Hi");
for (var i=0; i<=len; i++ )
{xfa.host.messageBox("Hi");
if ( xfa.resolveNode("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA["+ i +"].FamilySF.SpouseSF.TextField1").rawValue == "X"){this.presence = "hidden";
}else{this.presence = "visible";
}
}
Siva407
Level 1
Level 1

Dear Radmar,

 i am attaching with screenshot for better understanding with hirarachy and code as well.

Scenario is like this a column in table has multiple subforms, so for each record the particular subform should be visible if it has data.

otherwise it should be invisble.

Note: i have renamed subforms names and made necessary code changes as well for better understanding.

Code_snippet.JPG

code:

 data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA[0].FamilySF.SpouseSF::initialize - (JavaScript, client)var len = xfa.resolveNodes("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA").length;
//var fields = xfa.form.subform.table.row.all;xfa.host.messageBox("Hi");
for (var i=0; i<=len; i++ )
{xfa.host.messageBox("Hi");
if ( xfa.resolveNode("data.#subform[0].#subform[2].#subform[3].GT_TABLE.DATA["+ i +"].FamilySF.SpouseSF.TextField1").rawValue == "X"){this.presence = "hidden";
}else{this.presence = "visible";
}
}
radzmar
Level 10
Level 10

So, you want to hide subform "SpouseSF" if the field "Textfield1" is empty? 

I have a couple of questions about that:

 

1. Where does the data come from for "Textfield1"? 

2. What's the loop for?

Siva407
Level 1
Level 1
1. Textfield1 I am filling it interface, it's actually flag I am setting it with "X" to hide subform
Siva407
Level 1
Level 1

2. I am using loop becoz for each record I will check value of textfield1 is "X" or not. If "X" than I will hide otherwise I will make the subform(SpouseSF) visible.

radzmar
Correct answer by
Level 10
Level 10

Well, you can simply use this JavaScript in the calculate event of SpouseSF.

 

this.presence = Textfield1.rawValue == "X" ? "visible" : "hidden";

 

View solution in original post