Loop through form elements

1,542 views
Skip to first unread message

Archit Garg

unread,
Feb 2, 2010, 5:43:07 AM2/2/10
to live...@googlegroups.com
Hi All,
 
I have created a form using Adobe LC Designer 8.2. Is there a way I can loop through all the form elements like 'Label', 'Text Field', 'Numeric Field' using javascript and retrieve the XML node bound to each one of them (using .saveXML())? I need to write a generic code which can work for any form...
 
Would highly appreciate if you can provide some javascript code along with your reply.
 
Please let me know if you need further information.
 
Thanks a lot.
Archit

Duane Nickull

unread,
Feb 2, 2010, 11:30:00 AM2/2/10
to live...@googlegroups.com
it depends on the process flow.

Do you want the form elements or the values?
Do you require the <data> while the user is still interacting with the
form or is it for a subsequent purpose?

Duane

22nd Century (my band) - http://22ndcenturyofficial.com/
Twitter - @duanechaos
Blog - http://technoracle.blogspot.com
********

> --
> You received this message because you are subscribed to the Google
> Groups "Adobe LiveCycle Developers" group.
> To post to this group, send email to live...@googlegroups.com.
> To unsubscribe from this group, send email to livecycle+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/livecycle?hl=en
> .

Archit Garg

unread,
Feb 2, 2010, 12:21:27 PM2/2/10
to live...@googlegroups.com
Hi Duane,
 
Many thanks for looking into it.
 
Here is the business process:
 
Step 1: There is a data entry team which is responsible for just entering the data into the system from the recieved paper forms. Requirement is that there should not be any client side validations and user should be able to save data in temporary storage.
 
Step 2: There is another team which is responsible for pulling out the form entries from temporary store, validate the entered form data and save them to permanent storage. Validation process can be triggered by:
1) Clicking on Validate button on the form
    1. Search for the required form entry
    2. Open the filled form
    3. Click on validate button available towards the bottom of the form
2) Clicking on "Validate" link against each row in search results
 
In both the cases user should see a read-only report with all the validation errors that exist on the form. An additional requirement, in case user is validating data by clicking on Validate button on the form, the form should get refreshed and border color of all the error'ed out fields should change to red.
 
Proposed Solution:
For temporary storage, an Oracle database table with a CLOB column is used to hold the complete form XML. As and when user clicks on Validate button or Validate link, a Java based validation engine reads each element of the form XML, applies required validations and saves the result into another database table from which the validation report is populated and displayed to the user in a new window.
 
During validation process, for each form field node in form data XML, for which specified validation rules failed, an attribute "error-flag" is set to true to indicate that this field has error. This form XML is then passed back to the calling program which invokes Adobe form rendering process and pass on the updated form data XML along with the XDP form.
 
Here are the two approaches that I think should work to achieve changing the border color of error'ed out fields to red:
1. Iterate over each form data node, extract the value of error-flag attribute, if it is true, get hold of the form element(s) which is bound to this data node, change its required display/border properties
2. Iterate over each form element, extract the data node it is bound to, check the value of error-flag and if it is true then change its display/border properties.
3. ??
 
Currently I am not even able to iterate over all the form elements or form data nodes. Please let me know if there is any other better approach for doing it or if you need further information in this regard.
 
Thanks
Archit

Duane Nickull

unread,
Feb 2, 2010, 12:48:12 PM2/2/10
to Adobe LiveCycle Developers
OK – this makes sense.  Based on this, I would leverage LC ES server for the validation and you can cut some costs (for syntax validation anyways).  This would make a good candidate for an LC ES process.  Here is a basic suggested way you might want to do it.

Step 1: Data Entry team gets a form on the client side, enters data.  The data captured in the form gets sent back to the server (XDP format) as part of a LC ES process and stored in the repository.   You could also extract the XML from the form and then iterate over it on the server.  This is much better than doing this on the client side as there are several bullet proof libraries for working with XML in Java (JDOM, Xerces etc.).

Step 2: Notifications are sent to the team (TEAM #2) responsible for validating letting them know there is work to be done and directing them to LC ES workspace.

   (variation) this gets escalated if not responded to in XX days/hours etc.

   (variation) you can build a custom java component and deploy it to the server to validate the form data syntactically and flag it to the reviewers based on your ruleset.  IT would be easy to flag the secondary form to have red borders based on this.
  By using Xerces or JDOM on the server, you get all the capabilities to walk the XML and marshall the fields into a java list or other structure to work with programmatically.  

  (variation) You can also subsequently load the data back into XDP forms and create tests against it based on the variables in the LC ES process flow.  Java + XML + XDP = a great set of tools to get this workflow done.

Step 3: TEAM #2 logs into workspace and loads the XML data into another form.  They can potentially see items flagged by the custom java component and also hit the “validate” button to validate the data.

Step 4: you can then use LC ES Content Services to store the data into a permanent location or even archive it in PDF/A

I am not sure if you want TEAM#2 to be able to correct entries when they validate but assuming you do, you can use the red borders to flag the data fields then pop up a message of exactly what is errant and flag it to be fixed.

You could also just send them a custom “error report” by walking the XML returned from Step 1 form submissions and have them correct the errors outside of the form via an AIR/Flex LC ES client.

To get down in the weeds, the code to do this exact set of operations will really depend on the data model behind the XML and the workflow as well for how you validate each node.  In general, there are code samples available and there are hooks to use form data variables for LC ES Business Processes so you can take a process action for each specific error in validation you encounter, whether they be tested for logic or syntax.

I can send you a set of resources for how to do most of this if you want.  There are also many third party companies on this list like Avoka, Ensemble, 4Point that can do this (sorry if I left any out) and Adobe PS is also available.  It should be easy to get this scenario enabled using LC ES.

Duane
********




On 2-Feb-10, at 2:43 AM, Archit Garg wrote:

Hi All,

I have created a form using Adobe LC Designer 8.2. Is there a way I can loop through all the form elements like 'Label', 'Text Field', 'Numeric Field' using javascript and retrieve the XML node bound to each one of them (using .saveXML())? I need to write a generic code which can work for any form...

Would highly appreciate if you can provide some javascript code along with your reply.

Please let me know if you need further information.

Thanks a lot.
Archit

Archit Garg

unread,
Feb 2, 2010, 1:54:16 PM2/2/10
to live...@googlegroups.com, Adobe LiveCycle Developers
Thanks Duane,

The solution really sounds good and I would like to get more information and resources around it. 

I would really appreciate if you can help me with the two approaches also that i mentioned in my email below (iterating over form elements/data nodes in JavaScript) 

Thanks again.
Archit  
--

Duane Nickull

unread,
Feb 2, 2010, 2:32:09 PM2/2/10
to Adobe LiveCycle Developers
I would not recommend using JavaScript to walk nodes of XML.  The Java XML parsers are much more robust and the code base you would have to maintain on the server side is much more elegant than writing javascript XML snippets for the client. Server side java would also have the advantage of being able customize much more easily.  

Having said that, if you really want to do this in javascript, you can walk the nodes using a standard iterator or use resolveNode(“<nameOfNode>”) replacing the <nameOfNode> with the actual name of the node.

Since you would want to validate each node upon it’s own ruleset, I don’t think making code that grabs a random node, then gets the element name to find the associated rule is the best way.  

I would strongly argue that this should be done server side though.

Duane
********




On 2-Feb-10, at 2:43 AM, Archit Garg wrote:

Hi All,

I have created a form using Adobe LC Designer 8.2. Is there a way I can loop through all the form elements like 'Label', 'Text Field', 'Numeric Field' using javascript and retrieve the XML node bound to each one of them (using .saveXML())? I need to write a generic code which can work for any form...

Would highly appreciate if you can provide some javascript code along with your reply.

Please let me know if you need further information.

Thanks a lot.
Archit

Archit Garg

unread,
Feb 2, 2010, 7:59:41 PM2/2/10
to live...@googlegroups.com, Adobe LiveCycle Developers
Hi Duane,

I completely agree with you and we are doing all the validations in Java only like I mentioned in my email. I need to iterate over form elements/data nodes to change the boder color of fields having validation error to red, based on the error flag attribute.

So my question here is how do i get to know the complete list of nodes that are available on form which can be passed to resolvenode funtion one by one? My intent here is to write a generic javascript code which works for all the forms I have. 

Sent from my iPhone
--

Raghu Nagireddy

unread,
Feb 2, 2010, 10:38:31 PM2/2/10
to Adobe LiveCycle Developers
Hello,

To get all nodes(fieldnames) in the form we can write java script
method which take main form as argument and loop thru if any subforms
inside.
Please see the code below.
-------------------------------
// Recursively traverse the node and sub-nodes for all field elements
function traverse(oParentNode)
{
var allChildElements;
var intNumElements;
var currentElement;
var i;
var j;

// Get all occurances of the parent element
intNumOccurances = oParentNode.all.length;

for (i=0; i < intNumOccurances; i++)
{
oCurrentParent = oParentNode.all.item(i);

// Get all the child nodes of the parent element
allChildElements = oCurrentParent.nodes;

// Total number of elements in the object
intNumElements = allChildElements.length;

// Loop through all the child elements
for (j=0; j < intNumElements; j++)
{
currentElement = allChildElements.item(j);

// If the element is another subform we'll recursively call the
function again
if (allChildElements.item(j).className == "subform")
{
traverse(currentElement);

// If the objects are fields or exclusive groups
} else {
if (currentElement.className == "field" ||
currentElement.className == "exclGroup")
{
//currentElement.name is field name so here we can get the field
value also if required.
//here just alerting the fieldnames
app.alert(currentElement.name);
}

}
}
}
} // end traverse function
------------------------------------------------

Placed the sample file here with the name of - getAllNodeElements.pdf

Regards,
Raghu.

On Feb 2, 7:59 pm, Archit Garg <archit.g...@gmail.com> wrote:
> Hi Duane,
>
> I completely agree with you and we are doing all the validations in  
> Java only like I mentioned in my email. I need to iterate over form  
> elements/data nodes to change the boder color of fields having  
> validation error to red, based on the error flag attribute.
>
> So my question here is how do i get to know the complete list of nodes  
> that are available on form which can be passed to resolvenode funtion  
> one by one? My intent here is to write a generic javascript code which  
> works for all the forms I have.
>
> Sent from my iPhone
>

> On 03-Feb-2010, at 1:02 AM, Duane Nickull <dnick...@adobe.com> wrote:
>
>
>
> > I would not recommend using JavaScript to walk nodes of XML.  The  
> > Java XML parsers are much more robust and the code base you would  
> > have to maintain on the server side is much more elegant than  
> > writing javascript XML snippets for the client. Server side java  
> > would also have the advantage of being able customize much more  
> > easily.
>
> > Having said that, if you really want to do this in javascript, you  
> > can walk the nodes using a standard iterator or use resolveNode(“<na
> > meOfNode>”) replacing the <nameOfNode> with the actual name of the n
> > ode.
>
> > Since you would want to validate each node upon it’s own ruleset, I  
> > don’t think making code that grabs a random node, then gets the elem
> > ent name to find the associated rule is the best way.
>
> > I would strongly argue that this should be done server side though.
>
> > Duane
>

> > On 2/2/10 10:54 AM, "Archit Garg" <archit.g...@gmail.com> wrote:
>
> > Thanks Duane,
>
> > The solution really sounds good and I would like to get more  
> > information and resources around it.
>
> > I would really appreciate if you can help me with the two approaches  
> > also that i mentioned in my email below (iterating over form  
> > elements/data nodes in JavaScript)
>
> > Thanks again.
> > Archit
>

> > On 2/2/10 9:21 AM, "Archit Garg" <archit.g...@gmail.com <mailto:archit.g...@gmail.com

> > On Tue, Feb 2, 2010 at 10:00 PM, Duane Nickull <duane.nick...@gmail.com
> >  <mailto:duane.nick...@gmail.com> > wrote:
> > it depends on the process flow.
>
> > Do you want the form elements or the values?
> > Do you require the <data> while the user is still interacting with  
> > the form or is it for a subsequent purpose?
>
> > Duane
>

> > 22nd Century (my band) -http://22ndcenturyofficial.com/<http://22ndcenturyofficial.com/
>
> > Twitter - @duanechaos
> > Blog -http://technoracle.blogspot.com<http://technoracle.blogspot.com


> > >  <http://technoracle.blogspot.com/<http://
> > technoracle.blogspot.com/> >
> > ********
>
> > On 2-Feb-10, at 2:43 AM, Archit Garg wrote:
>
> > Hi All,
>
> > I have created a form using Adobe LC Designer 8.2. Is there a way I  
> > can loop through all the form elements like 'Label', 'Text Field',  
> > 'Numeric Field' using javascript and retrieve the XML node bound to  
> > each one of them (using .saveXML())? I need to write a generic code  
> > which can work for any form...
>
> > Would highly appreciate if you can provide some javascript code  
> > along with your reply.
>
> > Please let me know if you need further information.
>
> > Thanks a lot.
> > Archit
>
> > ---

> > Adobe LiveCycle Enterprise Architecture -http://www.adobe.com/products/livecycle/
> >  <http://www.adobe.com/products/livecycle/>
> > My TV Show -http://tv.adobe.com/show/duanes-world/<http://tv.adobe.com/show/duanes-world/

> > ---
> > Adobe LiveCycle Enterprise Architecture -http://www.adobe.com/products/livecycle/

> > My TV Show -http://tv.adobe.com/show/duanes-world/
> > My Blog –
>
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Duane Nickull

unread,
Feb 2, 2010, 10:46:52 PM2/2/10
to live...@googlegroups.com
THat depends again upon where this will happen and what the flag is and whether or not the flags themselves can be done generically. From what I understand you do not want the first user to have this functionality.  This means that the form has to be persisted somewhere before the second group looks over the form.  If they are simply saving it as a form, you will have to validate based on some criteria.  That criteria is logically not going to be the same for every form field.

For example, you have 5 fields - three are dates and two are text fields.  YOu can test the dates to see if they are > currentDate but if you run that same test over the text nodes, it presents an issue.

Here is what we would need as minimum criteria to enable this:

- a list of all nodes for all documents you will test;
- a set of criteria upon which to judge each node as to whether validated == (true || false);
- the methodology for which you want to trigger the validation
- the format the form date will be in where the trigger is pulled.

Without that, there would be no point to iterate over the form fields.  The code to iterate over all fields and grab their values is easy but this will be slow if you have to perform a lot of if..else loops or case..switch statements.

Can you send us your actual form?

Duane

********
22nd Century (my band) - http://22ndcenturyofficial.com/
Twitter - @duanechaos
********


Duane Nickull

unread,
Feb 2, 2010, 10:48:16 PM2/2/10
to live...@googlegroups.com
This part is the easy part though. The main question that looms is
how to test each node for validation once you have it. If it is
simply to test whether there is a value there, it will work but if the
validation criteria is complex and contextual, this will get bloated
really fast IMO.

Duane

********
22nd Century (my band) - http://22ndcenturyofficial.com/
Twitter - @duanechaos

Archit Garg

unread,
Feb 3, 2010, 3:27:02 AM2/3/10
to live...@googlegroups.com

Thanks a lot Raghu/Duane,

This is exactly what I was looking for.
 
I also found similar scripting example available at the following URL: http://www.adobe.com/devnet/livecycle/designer_scripting_samples.html/ --> Processing all fields on a form
 
Here is the code that is working for me:
 
EmployeeForm.#variables[0].GenericScript - (JavaScript, client)
function ProcessAllFields(oNode)
{
 if (oNode.className == "exclGroup" || oNode.className == "subform"  || oNode.className == "subformSet" || oNode.className == "area")
 {
  for (var i = 0; i < oNode.nodes.length; i++)
  {
   var oChildNode = oNode.nodes.item(i);
   ProcessAllFields(oChildNode);
  }
 }
 else if (oNode.className == "field")
 {
  var xmlString = oNode.dataNode.saveXML();
 
  if(xmlString.indexOf("valid=\"false\"") != -1)
  {
   oNode.border.edge.color.value = "255,0,0";
  } 
  if(xmlString.indexOf("editable=\"false\"") != -1)
  {
   oNode.access = "readOnly";
   oNode.fillColor = "238,233,233";
  }   
 }
}

There is just one issue with this code, if "dataNode" property does not exist for any oNode, the code breaks. I read through the documentation and I found that there is a method isPropertySpecified("<propertyName>") which tells us if a given property exists for a node or not but somehow it is not working as expected. It looks like this method is not supported in JavaScript. The updated "else if" code would look like:

 else if (oNode.className == "field" && oNode.isPropertySpecified("dataNode"))
{
 do stuff;
}

Can you please help?

Thanks
Archit
EmployeeForm.xsd
EmployeeForm.xml
EmployeeForm.xdp
Reply all
Reply to author
Forward
0 new messages