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
> .
********
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
--
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/>
My Blog – http://technoracle.blogspot.com/ <http://technoracle.blogspot.com/>
My Band – http://22ndcenturyofficial.com/ <http://22ndcenturyofficial.com/>
Twitter – http://twitter.com/duanechaos <http://twitter.com/duanechaos>
--
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/
>
> > My Blog –http://technoracle.blogspot.com/<http://technoracle.blogspot.co
> > m/>
> > My Band –http://22ndcenturyofficial.com/<http://22ndcenturyofficial.co
> > m/>
> > Twitter –http://twitter.com/duanechaos<http://twitter.com/duanecha
> > os>
>
> > ---
> > 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
********
22nd Century (my band) - http://22ndcenturyofficial.com/
Twitter - @duanechaos
Blog - http://technoracle.blogspot.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?