Hi,
I'm not able to access xform model and it's related instance through java script, While searching in google, I found the following example, var model = document.getElementById("myModel"); var instance = model.getInstanceDocument("myInstance"); I tried to use the above script, but I got null value for "document.getElementById("myModel");" here "myModel" is the id of model that I used in the xform(<xf:model id="myModel">) Please help me how to pass exact id to get xform model in java script Thanks in Advance.. |
Administrator
|
Hi Vignesh,
In Orbeon Forms, the XForms isn't directly accessible from JavaScript, for performance and security reasons. May I ask what you need to do next with the instance in JavaScript? In general, it is better, again for performance and security, to keep that instance on the server-side only, and use an XForms submission to pass that instance to another system that might need it. Alex
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
This post was updated on .
Hi Alex,
I used below step to update instance from javascript, Now it is working for me. ORBEON.xforms.Document.dispatchEvent <xf:insert if="xxforms:valid(instance('unparsed-xml'))" nodeset="instance('countries')" origin="saxon:parse(instance('unparsed-xml'))"/> Thanks, Vignesh Kanna M |
This post was updated on .
In reply to this post by Alessandro Vernet
Hi Alex,
I'm facing one more issue, I'm calling Xform event from Java script by using the following code. ORBEON.xforms.Document.dispatchEvent For example I'm calling ORBEON.xforms.Document.dispatchEvent under DOMFocusOut of Input field1. Let say I have another event under DOMFocus of Input field2. In case If I tab out from field1 to field2, at this time ORBEON.xforms.Document.dispatchEvent is called after the DOMFocus event of field2. Expectation: ORBEON.xforms.Document.dispatchEvent should call only at DOMFocusOut event of field1, It should not call after DOMFocus event of field2 Note:I'm guessing ORBEON.xforms.Document.dispatchEvent calling asynchronously, If so how to make it as synchronous? Please help me on this issue |
Administrator
|
Hi Vignesh,
What do you mean by "dispatchEvent is called after the DOMFocus event of field2"? Calling dispatchEvent() will queue an event, which will sent to the server using Ajax, and is thus asynchronous by nature. Alex
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex,
"dispatchEvent is called after the DOMFocus event of field2"---> I mean dispatchEvent method called after the DOMFocus event of field2, in my above example dispatchEvent is called on DOMFocusOut event of field1.. So I'm expecting dispatchEvent to be called at the time of DOMFocusOut of field1, it should not called after DOMFocus event of field2. As per my understand, since you mentioned "Calling dispatchEvent() will queue an event". I think my requirement can't be achieved right? please confirm Thanks, Vignesh Kanna M |
Administrator
|
Hi Vignesh,
Correct. JavaScript events run in the "right order". XForms events run in the "right order". However, if you do something in JavaScript that runs something in XForms, or vice versa, that "something" will run asynchronously, since "JavaScript" and "XForms" communicate through Ajax, and the "A" stands for "asynchronous". When you encounter a case like this, you either need to rethink the need for things to run synchronously, or do everything on the same side, that is all in XForms, preferably, or all in JavaScript. Does this make sense? Alex
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
This post was updated on .
Hi Alex,
Thanks for replying, I got your point, As per my requirement, I want XForm & Java Script code need to be run synchronously. Regards, Vignesh |
Administrator
|
Hi Vignesh,
Understood, and "unfortunately" browsers don't support running client-side and server-side code synchronously isn't possible. I am using quotes around "unfortunately", as there are good reasons they browsers support this, as this would result in the browser appearing "frozen" while it waits for a response from the server. Alex
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex,
Yes you are correct... However if we have control over the synchronous or asynchronous behavior then it is more configurable. Regards, Vignesh Kanna M |
Administrator
|
Hi Vignesh,
I understand. Have you found way around this to handle the scenario that initially raised this issue? Alex
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
This post was updated on .
Hi Alex,
I Did the following steps for work around, 1.Java script will be called synchronously and I'm using <xf:load resource="javascript:JSFunctionName"/> to call the JS function. Form the function I'm calling "ORBEON.xforms.Document.dispatchEvent" 2.As we know the that we can able to pass parameter values in "ORBEON.xforms.Document.dispatchEvent" using properties: {p1: "Value 1")}. 3.Now I changed the logic inside the dispatchEvent based on the synchronized parameter values. However event will be called asynchronously, the logic is executed based on the synchronized values. Thanks, Vignesh Kanna M |
Administrator
|
Vignesh, got it, and I'm glad you found a way to make this work. Things happening asynchronously can be pretty tricky.
Alex
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Free forum by Nabble | Edit this page |