How can I use xforms:load to embed a javascript in an xforms page and then call it?

391 Views Asked by At

I know we call invoke a JavaScript method using xf:load in the xforms-ready event of the model.

<xf:load resource="javascript:myFunction()" />

But how can I embed JavaScript? I.e. I want to dynamically generate javascript from a resource, embed it in an element and then invoke it using the method above?

1

There are 1 best solutions below

0
On

If you're writing XForms "by hand", you can include your own JavaScript by adding a <script> inside the <head> of your page. There is really nothing specific to XForms here. With Orbeon Forms, you would typically use the xh prefix to denote this is something from HTML:

<xh:script src="/path/to/your/script.js" type="text/javascript"/>

If you're using Form Builder to create the form, then you'll want to use the oxf.fr.js.custom.uri.*.* property to reference JavaScript files to include.