Hi,Is there any supported way of explicitly setting an event for eg. onSave = true OR onSaveValid = true so that relevant event handlers may be invoked as and when desired? Any pointers please?TIA
My requirement is to set an event's state equal to true or false so that the function yyy that I have registered as IWX.addFormHandler("onSaveValid", yyy) may be invoked as and when desired. For example,1. I registered a listener for the onSave event which invoked a function Foo.2. When the processing inside Foo completes, I want to make an explicit call to another function FooYou. The FooYou function is registered for the event onSaveValid. I want to invoke the FooYou function by changing the onSaveValid event state to true.In other words, I want to explicitly change the state of an event like onSaveNameSpecified etc so that the relevant event handler attached to it is automatically invoked. Does this make sense now?Any method of doing this that you know of?
The Save process actually involves several sub processes.The sequence of events involved is [color=red]onSave->onSaveValid->onSaveNameSpecified->onSaveDone.[/color]
Now if you registed a function with onSave,FormsPublisher validates the form. If the form is valid, the onSaveValid event is generated, and any registered user script function is invoked. And then it moves on to the next even.
There is an excellent flowchart diagram in the formAPI pdf explaining this. You may like to have a look at that as well.
Thanks Mav. I have gone through that diagram before asking this query.My concern here is to find out a way to take control of generating the FormAPI events like onSave, onSaveValid etc. on will(as and when desired) in the flow.I need to have the control to deal with the asynchronous nature of the callServer request. Though I've already dealt with my requirement in some way or other, I am just curious to know if there's any supported method by which I can control the execution, generation of events and be able to change their state at will.Let me know if something like that is possible.
I don't believe what you are asking for is possible. When you do a callServer (asynchronous operation) as part of any one of the chain-of-events, the handler from which you invoke the callServer must return false - at which time, the chain-of-events is terminated, and it is up to you to then "manually" perform any subsequent functions that were not run due to the termination of the chain-of-events.Most often (in my experience) the event handler is set for onSaveValid in order to programmatically name the DCR. The callServer script is responsible for calling back to either an "ok" or "not-ok" function - the "ok" function would then perform a "save" and use a timeout loop to check to see when the save is completed (see the documentation on IWDCRInfo.getStatus)
I believe if I could just get hold of the FormAPI JS functions and variables(IW default), I could just make it, though it'd be kind of a "hack". Please let me know your thoughts on this one.
Also, if you're doing all this to deal with the async nature of callserver()...then why not just not use callserver() and roll your own?
Well Bjorn, in that case, can you suggest an alternative to the callServer. Invoking a Perl script from Javascript seems to be not a simple task due to the limitations of Javascript. However, has someone tried it before? Any pointers?
Sure -- keep in mind I'm only addressing the comment you made "I need to have the control to deal with the asynchronous nature of the callServer request". So you'll of course need to see if what I'm suggesting truly does fit into your needs. 1 - Drop some sort of framework that supports ajax into the DCT. JQuery. Mootools, whatever you like. There are a thousand different ways to do this, actually, but they're all conceptually the same.2 - Make sure to configure your Ajax objects to make your requests synchronous. Usually pretty straightforward. The risk is that the browser (FormAPI) hangs if the request hangs. The reward depends on whatever reason you had for being frustrated with having to deal with async requests of callserver() bumping into each other (or whatever).3 - Use it to call your CGI (Perl script) to do whatever it needs to do. You may need to adjust your CGI to return something that is more "ajax-friendly", like XML. This is pretty high-level. I could write some actual code or more specific instrux, but I'm not sure exactly what you need to do. Besides, half the fun is figuring things out on your own.
When the form loads for the first time, X is invoked and so the IPL is invoked. When I fill the data and click Save or Finish, Y is also invoked if data entered in the DCR is valid. Invoking Y before the IPL finishes its execution(I don't know why the IPL is not able to finish the execution in such a long-time), leads me to a state when there is no name defined for the DCR and so I get a pop-up to provide a name to save it(which I certainly don't want since I want to autoname it). Thus, my concern was to synchronize the callServer method so that Y is executed only after the IPL finishes the execution.
var xhr; //SOMEHOW GET XMLHTTPREQUEST OBJxhr.open("get","PATH TO YOUR IPL",false);//maybe use IWDatacapture.displayMessage(""); to inform user that info is loading...xhr.send(null);if (xhr.readyState == 4 && xhr.status == 200){ //USE xhr.ResponseXML to get value and FormAPI to set DCR name //USE FormAPI to save the form}//don't forget to add your own error handling, etc...
Any motivating ideas?