Expand my Community achievements bar.

SOLVED

Help with Button to Display custom Alert

Avatar

Level 3

I have the following code I found and tweaked for our purposes, however I am having difficulty modifying the code so that it only reports back all dropdown fields in my form, which are required, and have a default value, which is "0".

I've been playing with it, and I thought the current code would work, but it displays required fields as well as fields containing "0"

Can someone please help me out.

 

var EmptyFields= new Array();
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
var oFields = xfa.layout.pageContent(nPageCount, "field");

var nNodesLength = oFields.length;
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
if ((oFields.item(nNodeCount).ui.oneOfChild.className != "button") && (oFields.item(nNodeCount).mandatory == "error" ||oFields.item(nNodeCount).rawValue == "0"))

{
EmptyFields.push(oFields.item(nNodeCount).name);
}
}
}
if (EmptyFields.length>0) {
app.alert("The first number indicates the Objective number** \n The second number indicates which score you missed. \n \n You have a zero rating in the Measuring Success section for the following ratings:\n\n" + EmptyFields.join("\n"));}
else
{
app.alert("All fields have been filled out successfully, and no errors were found.", 3)
}
1 Accepted Solution

Avatar

Correct answer by
Level 3

I figured it out, for anyone who has a similar issue.

 

What I did is changed this piece of code:

if ((oFields.item(nNodeCount).ui.oneOfChild.className != "button") && (oFields.item(nNodeCount).mandatory == "error" ||oFields.item(nNodeCount).rawValue == "0"))

to this:

if ((oFields.item(nNodeCount).ui.oneOfChild.className != "button") && (oFields.item(nNodeCount).mandatory == "error" && (oFields.item(nNodeCount).rawValue == "0")))

and it works like a charm now

View solution in original post

1 Reply

Avatar

Correct answer by
Level 3

I figured it out, for anyone who has a similar issue.

 

What I did is changed this piece of code:

if ((oFields.item(nNodeCount).ui.oneOfChild.className != "button") && (oFields.item(nNodeCount).mandatory == "error" ||oFields.item(nNodeCount).rawValue == "0"))

to this:

if ((oFields.item(nNodeCount).ui.oneOfChild.className != "button") && (oFields.item(nNodeCount).mandatory == "error" && (oFields.item(nNodeCount).rawValue == "0")))

and it works like a charm now