Unable to hide subform in table cell dynamically

Siva407

03-05-2020

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");

 

 

Accepted Solutions (1)

Accepted Solutions (1)

radzmar

MVP

07-05-2020

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

 

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

 

Answers (4)

Answers (4)

radzmar

MVP

06-05-2020

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

06-05-2020

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";
}
}

Siva407

06-05-2020

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";
}
}

radzmar

MVP

05-05-2020

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;