Help with Button to Display custom Alert | Community
Skip to main content
February 9, 2022
Solved

Help with Button to Display custom Alert

  • February 9, 2022
  • 1 reply
  • 576 views

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) }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by commalliance

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

1 reply

commallianceAuthorAccepted solution
February 9, 2022

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