Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Subform Question

Avatar

Level 2
I have a LiveCycle dynamic form that has a subform that allows the user to add additional line (works great).



What I am stumbling with is the validation working on all rows. The validation script works on the initial row, but does not flow to the added rows. What I am think might work, is to look at the subform occurrance and qualify off that, but I don't have any idea how to do it.



If someone could let me know if I am looking in the right direction, has a better way, or has run up against this, any information would be greatly appreciated.
7 Replies

Avatar

Former Community Member
can you paste the script here? Is it universal?

Avatar

Level 2
Chris-



Sorry about the delay. I have been out of the office. Here is the script.



----- form1.Header.CompanyInfo.Request.AddALine::click - (JavaScript, client) ----------------------



////Validate TaxType has been selected

var aVar = 0

if ((Detail.TaxType.rawValue == null) && (Detail.ItemNum.rawValue != null))

{

app.alert("Please select a tax type.");

aVar = 1;

}

else

{

aVar = 0;

}

////Validate Yr

var bVar = 0

if ((Detail.TaxType.rawValue > 0) && (Detail.Yr.rawValue == null))

{

app.alert("Please enter the year for the request.");

bVar = 1;

}

else

{

bVar = 0;

}

////Validate Qtr

var cVar = 0

if ((Detail.TaxType.rawValue >= 1) && (Detail.Qtr.rawValue == null))

{

app.alert("Please enter the quarter for the request.");

cVar = 1;

}

else if ((Detail.Qtr.rawValue < 1) || (Detail.Qtr.rawValue >4))

{

app.alert("Please enter a valid number.");

Detail.Qtr.rawValue = null;

cVar = 1;

}

else

{

cVar = 0;

}

////Validate State

var dVar = 0

if ((Detail.TaxType.rawValue == 3) && (Detail.J_State.rawValue == null))

{

app.alert("Please select the state needed.");

dVar = 1;

}

else

{

dVar = 0;

}

////Validate Local

var eVar = 0

if ((Detail.TaxType.rawValue == 4) && (Detail.J_Local.rawValue == null))

{

app.alert("Please enter the local jurisdiction needed.");

eVar = 1;

}

else

{

eVar = 0;

}

if ((aVar == 0) && (bVar == 0) && (cVar == 0) && (dVar == 0) && (eVar == 0))

{

Request._Detail.addInstance (true);

}



Thanks so much form looking at this for me.

Avatar

Former Community Member
ok, it's all clear now. Please send me this form and I will try to fix it and then I will write a solution here.



My e-mail is kordulasinski.krzysztof@gmail.com

Avatar

Former Community Member
ok, so, first of all it would be nice to know, how many instances do we have:

var numberOfDetail = xfa.resolveNodes("Detail[*]").length;



Then we have to make sure, that we check all the instances, so:

for(var i = 1 ; i <= numberOfDetail ; i++)

{



and then we have to make the validation universal so we gonna reference the fields by using their index. So if you want to access a field value, please make it like this:

var fTaxType = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].TaxType");

if (fTaxType.rawValue == null)



It would be nice to set focus on the perticular field (with error):

this.rawValue = xfa.host.setFocus(fTaxType);



Tell me if you got it all and if it works.

Avatar

Level 2
Chris

I have added what you have above and I am now having a different error. The validation popups are working on the first line only. The debugger is showing the following if I click addALine on the second instance with no date entered or if I have selected the TaxType and have not completed the request. Also the setFocus does not seem to be working, the curse is not visible in the called field.



GeneralError: Operation failed.

XFAObject.resolveNode:3:XFA:form1[0].Header[0].CompanyInfo[0].Request[0].AddALine[0]:click

SOM expression returned list when single result was expected



This is the script now



----- form1.Header.CompanyInfo.Request.AddALine::click - (JavaScript, client) ----------------------



////Validate TaxType has been selected

var aVar = 0

var numberOfDetail = xfa.resolveNode("Detail[*]").length

var i = 1 <= numberOfDetail ; i++

var fTaxType = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].TaxType");

if (fTaxType.rawValue == null)

{

xfa.host.setFocus("fTaxType");

app.alert("Please select a Tax Type.");

aVar = 1;

}

else

{

aVar = 0;

}

////Validate Yr has been selected

var bVar = 0

var fYr = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].Yr");

if (fYr.rawValue == null)

{

xfa.host.setFocus("fYr");

app.alert("Please select a Year.");

bVar = 1;

}

else

{

bVar = 0;

}

////Validate Qtr

var cVar = 0

var fQtr = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].Qtr");

if ((fTaxType.rawValue >= 1) && (fQtr.rawValue == null))

{

xfa.host.setFocus("fQtr");

app.alert("Please enter the quarter number.");

cVar = 1;

}

else

{

cVar = 0;

}

////Validate State

var dVar = 0

var fJ_State = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].J_State");

if ((fTaxType.rawValue == 3) && (fJ_State.rawValue == null))

{

xfa.host.setFocus("fJ_State");

app.alert("Please select a state.");

dVar = 1;

}

else

{

dVar = 0;

}

////Validate Local

var eVar = 0

var fJ_Local = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].J_Local");

if ((fTaxType.rawValue == 4) && (fJ_Local.rawValue == null))

{

xfa.host.setFocus("fJ_Local");

app.alert("Please select enter the local jurisdiction.");

eVar = 1;

}

else

{

eVar = 0;

}

////////////Argument to add a line

if ((Request._Detail.count == Request._Detail.max - 1) && ((aVar == 0) && (bVar == 0) && (cVar == 0) && (dVar == 0) && (eVar == 0)))

{

app.alert("The maximum number of items allowed per form is 10./n/nThis is the last entry for this request",3,0);

Request._Detail.addInstance (true);

}

else if ((aVar == 0) && (bVar == 0) && (cVar == 0) && (dVar == 0) && (eVar == 0))

{

Request._Detail.addInstance (true);

}

Avatar

Former Community Member
I'm pasting the whole script, b/c I see some errors in yours. You will be able to figure it out.



----- form1.Header.CompanyInfo.Request.AddALine::click: - (JavaScript, client) ---------------------



//check the number of DETAIL instances

var numberOfDetail = xfa.resolveNodes("Detail[*]").length;



//start a FOR loop on all the DETAILS

for(var i = 1 ; i <= numberOfDetail ; i++)

{



////Validate TaxType has been selected

var aVar = 0



//this is a way to get the TaxType field using the "i" index. It is "i-1" b/c it uses the 0 based index. I know we can do it another way, but it works

var fTaxType = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].TaxType");

if (fTaxType.rawValue == null)

{

app.alert("Please select a tax type.");

aVar = 1;

this.rawValue = xfa.host.setFocus(fTaxType);

}

else

{

aVar = 0;

}

////Validate Yr

var bVar = 0

if ((Detail.TaxType.rawValue >= 0) && (Detail.Yr.rawValue == null))

{

app.alert("Please enter the year for the request.");

bVar = 1;

}

else

{

bVar = 0;

}

////Validate Qtr

var cVar = 0

if (((Detail.TaxType.rawValue == 1)|| (Detail.TaxType.rawValue == 2) || (Detail.TaxType.rawValue == 3) || (Detail.TaxType.rawValue == 4)) && (Detail.Qtr.rawValue == null))

{

app.alert("Please enter the quarter for the request.");

cVar = 1;

}

else if (((Detail.TaxType.rawValue == 1)|| (Detail.TaxType.rawValue == 2) || (Detail.TaxType.rawValue == 3) || (Detail.TaxType.rawValue == 4)) && (Detail.Qtr.rawValue < 1) || (Detail.Qtr.rawValue > 4))

{

app.alert("Please enter a valid number.");

Detail.Qtr.rawValue = null;

cVar = 1;

}

else

{

cVar = 0;

}

////Validate State

var dVar = 0

if ((Detail.TaxType.rawValue == 3) && (Detail.J_State.rawValue == null))

{

app.alert("Please select the state needed.");

dVar = 1;

}

else

{

dVar = 0;

}

////Validate Local

var eVar = 0

if ((Detail.TaxType.rawValue == 4) && (Detail.J_Local.rawValue == null))

{

app.alert("Please enter the local jurisdiction needed.");

eVar = 1;

}

else

{

eVar = 0;

}

////////////



}



if ((aVar == 0) && (bVar == 0) && (cVar == 0) && (dVar == 0) && (eVar == 0))

{

Request._Detail.addInstance (true);

}

Avatar

Level 2
Chris



Thank you so much. You are a great teacher for resolveNode. I have added the other fields to resolveNode and the verification works perfectly on all fields and instances.



I am posting the completed script so that if someone has the same question they can refer to what you have taught me.



----- form1.Header.CompanyInfo.Request.AddALine::click - (JavaScript, both) ------------------------



//check the number of DETAIL instances

var numberOfDetail = xfa.resolveNodes("Detail[*]").length;



//start a FOR loop on all the DETAILS

for(var i = 1 ; i <= numberOfDetail ; i++) {



////Validate TaxType has been selected

var aVar = 0



//this is a way to get the TaxType field using the "i" index. It is "i-1" b/c it uses the 0 based index. I know we can do it another way, but it works

var fTaxType = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].TaxType");

var fYr = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].Yr");

var fQtr = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].Qtr");

var fJ_State = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].J_State");

var fJ_Local = xfa.resolveNode("form1.Header.CompanyInfo.Request.Detail["+ (i-1) +"].J_Local");

if (fTaxType.rawValue == null)

{

app.alert("Please select a tax type.");

aVar = 1;

}

else

{

aVar = 0;

}

////Validate Yr

var bVar = 0

if (fYr.rawValue == null)

{

app.alert("Please enter the year for the request.");

bVar = 1;

}

else

{

bVar = 0;

}

////Validate Qtr

var cVar = 0

if (((fTaxType.rawValue == 1) || (fTaxType.rawValue == 2) || (fTaxType.rawValue == 3) || (fTaxType.rawValue == 4)) && (fQtr.rawValue == null))

{

app.alert("Please enter the quarter for the request.");

cVar = 1;

}

else if (((fTaxType.rawValue == 1) || (fTaxType.rawValue == 2) || (fTaxType.rawValue == 3) || (fTaxType.rawValue == 4)) && (fQtr.rawValue < 1) || (fQtr.rawValue > 4))

{

app.alert("Please enter a valid quarter number.");

fQtr.rawValue = null;

cVar = 1;

}

else

{

cVar = 0;

}

////Validate State

var dVar = 0

if ((fTaxType.rawValue == 3) && (fJ_State.rawValue == null))

{

app.alert("Please select the state needed.");

dVar = 1;

}

else

{

dVar = 0;

}

////Validate Local

var eVar = 0

if ((fTaxType.rawValue == 4) && (fJ_Local.rawValue == null))

{

app.alert("Please enter the local jurisdiction needed.");

eVar = 1;

}

else

{

eVar = 0;

}

////////////



}



////////////Argument to add a line

if ((Request._Detail.count == Request._Detail.max - 1) && ((aVar == 0) && (bVar == 0) && (cVar == 0) && (dVar == 0) && (eVar == 0)))

{

app.alert("The maximum number of items allowed per form is 10.\n\nThis is the last entry for this request",3,0);

Request._Detail.addInstance (true);

}

else if ((aVar == 0) && (bVar == 0) && (cVar == 0) && (dVar == 0) && (eVar == 0))

{

Request._Detail.addInstance (true);

}