Highlighted

Execute Javascript code first, before individual initialize events?

Avatar

Avatar

andygoldstein

Avatar

andygoldstein

andygoldstein

14-11-2008

Is there a way to have Javascript code run at the very beginning of the form process, before any specific individual form component's initialize event happens? I have a table and some of the content depends on the data values from XML, but I need to be able to evaluate every subelement in a repeating section of my input data before beginning to render content (i.e. the value of some text depends on if all "Foos" in my XML have the same value for their "Bar" element).



Or is there some initialize event I can use that is guaranteed to run first, before the depth-first initialization process begins?



Thanks,

Andy

Replies

Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

16-11-2008

Did you try the initialization event on the field?
Highlighted

Avatar

Avatar

andygoldstein

Avatar

andygoldstein

andygoldstein

17-11-2008

Which field?



Here's a better description of my scenario (it's not the best example, but it works). I have XML input, and the XML contains a list of cars. Each car element has several child elements, one of which is hasCruiseControl. The possible values for hasCruiseControl are yes, maybe, and no.



I need to display a table of all the cars. In one of the cells, I need to display the value of hasCruiseControl. I also need to display a footnote next to the value, and the corresponding footnote text at the bottom of the page. Here's where it gets tricky. If all cars in the XML list have hasCruiseControl=yes or hasCruiseControl=no, then I only need to show 1 footnote, and that footnote's number is (3). If all the cars in the list have hasCruiseControl=maybe or hasCruiseControl=no, then I only need to show 1 footnote, and that footnote's number is also (3), but the text at the bottom of the page for footnote (3) will be different. If some of the cars in the list have hasCruiseControl=yes and some have hasCruiseControl=maybe, then I need to show 2 footnotes, whose numbers will be (3) and (4). (hasCruiseControl=no has no footnote; it is just yes and maybe that generate footnotes.)



So I need to be able to evaluate ALL of the XML data prior to an initialize event for an individual table cell, because I need to know the cardinality of the yes's and the maybe's beforehand. I'd prefer not to have to loop through all my XML data every time for each cell.



Does this make more sense? Is there a way to run Javascript code first, prior to form object initialization? Should I attach my code to a prior object in the hierarchy that I know will be initialized before the table? (I would consider this a bit of a hack, but I think it would work.)



Thanks,

Andy
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

17-11-2008

So lets try a different approach. Let the form get driven by the data (layoutis complete) then just before we hand the form to the user we check for your crusie control conditions and adk=just the footnote text accordingly. You could see how many Car subforms were creatded then test the has cruise control for each and then do what needs to be done.



This way you are only executing the code once. You woudl put the code on the DocReady event of the root node of the heirarchy.
Highlighted

Avatar

Avatar

andygoldstein

Avatar

andygoldstein

andygoldstein

17-11-2008

That sounds like what I've been looking for. Once the layout is complete, will I be able to show/hide objects as needed? As I mentioned above, I might be showing 2 footnotes, or 1, or 0, depending on if there is yes+maybe, yes or maybe, or no only.



Also, how would the Javascript look for looping through the subforms that were created via the data repetition?



Thanks,

Andy
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

18-11-2008

First you would have to get a count of the number of subforms. You can use the subformname.instanceManager.count. Now that you know how many that you have you can use that value for the upper limit of your counter.



To address each individual field you will require an occurance number and that is on the subform container of the field. So if you have TextField1 in subform1 on Page1 in form1 your expression woudl look like this:



form1.Page1.subform1[occurancenumber].TextField1.property or method that you want



Now the tricky part. Javascrit does not like square brackets, so you have to use the xfaresolveNode("string representing SOM Expression").



So if you wanted the rawValue and you were in a loop where i is the counter value your expresion woudl look like this:



xfa.resolveNode("form1.Page1.subform1[" + i + "]").TextField1.rawValue



Make sense?
Highlighted

Avatar

Avatar

andygoldstein

Avatar

andygoldstein

andygoldstein

18-11-2008

Yes, it's quite clear - thanks for all your help!



Andy