Re: [Xsltforms-support] How to choose when a JS class will be instanciated?
Brought to you by:
alain-couthures
From: Grégoire C. <gco...@gm...> - 2010-06-03 09:20:24
|
Hi, I solved this problem by attaching my global variable to the window. Grégoire Le 2 juin 2010 14:57, Grégoire Colbert <gco...@gm...> a écrit : > Hi, > > I have written a JS class ("MapHandler") that should respond to various > XForms events. The XForm tag that instanciates the class looks like: > > <xf:action ev:event="xforms-model-construct-done"> > <xf:load> > <xf:resource value="concat('javascript:var mapHandler = new > MapHandler();mapHandler.initialize(' , > instance('instance-configuration')/default/latitude , ',' , > instance('instance-configuration')/default/longitude , ')' )" /> > </xf:load> > </xf:action> > > As you can see, the "mapHandler" object is created just before the call to > the "initialize" method. In this case, everything works fine. > > Today, I wanted to create another event handler, so I added this inside a > <select1>: > > <xf:action ev:event="xforms-select"> > <xf:load> > <xf:resource value="concat('javascript:mapHandler.centerMap(' , > instance('instance-towns')/latitude , ',' , > instance('instance-towns')/longitude , ')' )" /> > </xf:load> > </xf:action> > > *Problem* : this JS code fails when the "xforms-select" event is received. > The error is "mapHandler is not defined". > > Looking at the generated code (using Mozilla's Web Developer extension), I > see that my JS code is wrapped inside a call to XPath.create(). This rises a > few questions... > > *Questions* : > 1) Does this mean that the "mapHandler" variable is local to the > XPath.create function? > 2) If so, is it possible to declare a global JS variable through XSLTForms? > 3) If so, how? > > Thank you, > Grégoire > > |