-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to pass values from XForms to JavaScript #2499
Comments
Quick analysis:
|
|
- clarify case classes to describe scripts - remove hookup of ServerScript as we don't use it - script parameters - output for JavaScript functions - evaluate when running xxf:script/xf:action - pass to Ajax response - pass to callUserScript() - consistency fixes for XMLReceiverSupport - remaining tasks for client code - handle xxf:param in Ajax response - callUserScript() must support extra parameters
Remaining tasks for client code:
|
Note that we don't support the |
Now moved to <xf:action event="xforms-enabled" type="javascript">
<xf:param name="uri" value="$my-uri"/>
<xf:param name="uid" value="$my-uid"/>
<xf:body>
console.log(uri, uid); // Parameters can be used directly
</xf:body>
</xf:action> |
I was wondering where the javascript function should be placed in order for |
If this is for a form you created with Form Builder, see the Adding your own JavaScript section of the documentation. And of course, just let us know if anything there isn't quite clear. |
That helps a lot, thank you very much. I will follow this section and see if everything works well. But I believe it will. |
@nettree OK, great. I'm glad this was useful. |
Rationale
We often want JavaScript code to be able to access a value stored in an instance or calculated in XPath either in read-only or read/write mode.
Current strategies
The current strategy is to insert in the page an
<xf:input style="display: none">
or<xf:output style="display: none">
and to then run JavaScript code onxforms-value-changed
with<xxf:script>
or to get/set the value withORBEON.xforms.Document.setValue()
and `ORBEON.xforms.Document.getValue()``. This has 2 main downsides:<xf:input>
or<xf:output>
.We can also use
<xf:load resource="javascript:myFunction($my-uri, $my-uid)"/>
with AVTs which allows passing dynamic parameters, but:Use
When the JavaScript code only needs read-only access to a value, it can be pushed to the JavaScript code on an event. Extending the syntax of
<xxf:script>
to allow parameters is all we need. The event handler could be declared with:Notes:
<xxf:param>
.<xxf:body>
which must be used if the<xxf:script>
contains one or more<xxf:param>
.event
object, on which thetarget
attribute is defined. We keep thisevent
object unchanged.In the future, instead of inlining the code, code could be declared in a function and referenced with the
function
attribute:In which case the function will be called as
myFunction(event, uri, uid)
. But this isn't necessary right now, especially considering that in an XBL we often want to call something likeYAHOO.xbl.fr.CodeMirror.instance(this).xformsValueChanged(newValue)
, wherenewValue
is a parameter.Implementation
Currently, the JavaScript inside
<xxf:script>
is put inside a function, inside a<script type="text/javascript">
:When
<xxf:param>
are defined, this would add them to the function:Currently, the Ajax response looks like:
When
<xxf:param>
are defined, it would pass the values for those parameters as:NOTE: This is migrated/adapted from a project on our old wiki from 2009.
The text was updated successfully, but these errors were encountered: