How to use external javascript function?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use external javascript function?

vicaed
This post was updated on .
Hi Everyone, I am following this documentation
https://doc.orbeon.com/configuration/properties/form-runner.html#adding-your-own-javascript,
for that I understand you can write your own javascrip functions and place
it in the recomended location. That I have done is create the folders
/forms/assets in
D:\servicios\tomcat\apache-tomcat-7.0.82\webapps\orbeon\WEB-INF\resources\forms\assets
(/forms/assets did not exist by default in my orbeon war so I created it),
then I understand that I can create my javascript code there. Also I have added in properties <property
    as="xs:string"
    name="oxf.fr.js.custom.uri.*.*"
    value="/forms/assets/myCode.js"/>. But the
question is, How to comunicate with these javascript functions from one
orbeon form?, how can javascript functions receive parameters from an orbeon
form? and how to get the result of the javascript function in the form?. I
donĀ“t find any example about how to do it.
I've tried the example described in this document https://doc.orbeon.com/xforms/client-side-javascript-api.html, just to understand how it works. The result is that if I write the javascript code in-line it works fine:
<xf:trigger id="boton-control" bind="boton-bind">
                                <xf:label ref="$form-resources/boton/label"/>                   
                                <xf:hint ref="$form-resources/boton/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                <xxf:script event="DOMActivate">
                                  var fooControl = ORBEON.jQuery('*[id $= "foo-control"]')[0];
                                  var fooValue = ORBEON.xforms.Document.getValue(fooControl);
                                  ORBEON.xforms.Document.setValue(fooControl, Number(fooValue) + 1);
                                </xxf:script>

But if I try the same, placing the javascript code out of the form (it is in D:\servicios\tomcat\apache-tomcat-7.0.82\webapps\orbeon\WEB-INF\resources\forms\assets\myCode.js), and I write in the form code:
<xf:trigger id="copyboton-control" bind="copyboton-bind">
                                <xf:label ref="$form-resources/copyboton/label"/>                   
                                <xf:hint ref="$form-resources/copyboton/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                <xxf:script event="DOMActivate" type="javascript">
                                          myFuncion(); //it is inside of the file myCode.js
                                 //I suposse the script should be load from the external source because the
                                   property tag
                                </xxf:script>

It does not work, it is like the script does not get load. Some idea about what I am missing?


--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orbeon+unsubscribe@googlegroups.com.
To post to this group, send email to orbeon@googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to use external javascript function?

vicaed
This post was updated on .
Ok I think I got resolve the problem. I had to inlcude in the header of the form:

<script type="text/javascript" src="/forms/assets/validaciones.js"/>

With this I get load the javascript code.

then inside of the trigger I call the function I want to use:
    <xf:action type="javascript" event="DOMActivate">                                   
                                   incrementValue();
     </xf:action> 

Please Alex, can you confirm if this is the correct way to do it ? and if so, why do you need include the url of the resource in local-property if you load it from the form header?

--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orbeon+unsubscribe@googlegroups.com.
To post to this group, send email to orbeon@googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to use external javascript function?

Alessandro  Vernet
Administrator
Hi Vincente,

You shouldn't need to add <script type="text/javascript"
src="/forms/assets/validaciones.js"/> to your form to include the
JavaScript; it should be automatically included based on the
`oxf.fr.js.custom.uri.*.*` you set.

Note that you might not see the your specific `validaciones.js` being loaded
by the browser, because it will be included in a combined JavaScript file.
Could this be what is happening? Also, is this for a form you're creating
with Form Builder? (I'm asking as this property is only used in the context
of Form Runner, hence the "fr" in the property name.)

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: How to use external javascript function?

vicaed
Hi Alex,

Yes I think it was the problem, I was working in the form builder context,
in form runner it works without the tag. thanks you!

--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: How to use external javascript function?

Alessandro  Vernet
Administrator
Excellent Vincente, I'm glad it works for you as expected with that property
within Form Runner!

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet