Accessing value of bound control of an XBL component

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

Accessing value of bound control of an XBL component

ncrofts
Hi,

I am trying to write an XBL component that as part of its requirement must take a reference to an instance value and then process this value with javascript when that value changes. There will be several instances of the component on a page.

e.g. <comp:test ref="instance('data'/value)"/>

I understand that by design it is not possible to access instance data directly from javascript. However I'm just not sure how to get access the unique id of the component that is bound to the referenced instance so that I could then use ORBEON.xforms.Document.getValue(...) to get the value.

Please can someone advise on how to reference the control's id or an alternative approach that will meet the need of handling the value in javascript within the component? An outline of the body of the XBL template I have is below.



<xforms:group xbl:attr="model context ref bind" xxbl:scope="outer" appearance="internal">

       
    <xxforms:variable name="binding" as="node()?" xxbl:scope="inner">
        <xxforms:sequence select="." xxbl:scope="outer" />
    </xxforms:variable>

   
    <xforms:group id="container" ref="$binding" xxbl:scope="inner">

       
        <xxforms:script ev:event="xforms-value-changed" type="text/javascript">
       
/* How do you access the components referenced value? */
                var controlValue = ORBEON.xforms.Document.getValue(??????????);  

                alert('VALUE: ' + controlValue);
               
        </xxforms:script>       

</xforms:group>


Regards,
Neil
 
Reply | Threaded
Open this post in threaded view
|

Re: Accessing value of bound control of an XBL component

ncrofts
Perhaps it may help if I clarify my aim. I'm actually trying to use XBL to wrap a media player control that is in the form of a javascript library. The URL of the media file must be constructed dynamically based on a value of another control (e.g xforms:input) also associated with the same data instance. Therefore the component interface will be of the form:

<comp:player ref="instance('data')/name"/>

where the value of the referenced instance data contains the name of a file which is then used to generate the final URL of the media file.

The problem I'm having is knowing how to access this value from javascript within the XBL component. I can incorporate a script that is invoked when the referenced data instance value changes, but I just can't see how you can then access the value from javascript so that I can create the URL and pass it to the media control.

<xxforms:script ev:event="xforms-value-changed" type="text/javascript">
       
    /* How do you access the components referenced value? */
    var controlValue = ORBEON.xforms.Document.getValue(??????????);  

    /* construct the url of the media file from this value. */
    alert('VALUE: ' + controlValue);
               
</xxforms:script>     


Can anybody suggest an appropriate way to solve this sort of problem in an Xforms XBL component?

Regards,
Neil
Reply | Threaded
Open this post in threaded view
|

Re: Re: Accessing value of bound control of an XBL component

Alessandro  Vernet
Administrator
Hi Neil,

If you just need to read the value from JavaScript, you can use an
xforms:output, and otherwise use an xforms:input, as you suggested. As
you've seen you can't use the id of the control from JavaScript, as it
will be prefixed in the generated HTML, since you could have multiple
instances of the component in the page. So instead, you need to get
the input or output by class name, starting from the "container"
element of your XBL. And you can get the container based on the `this`
you get when your event handler is called (`this` point to the event
target). I recommend you put your JavaScript code in a "companion
class", as done with the controls that ship with Orbeon Forms. See for
instance tinymce.xbl [1] and how the "client-value" and "server-value"
are then accessed from tinymce.js [2].

[1] https://github.com/orbeon/orbeon-forms/blob/master/src/resources-packaged/xbl/orbeon/tinymce/tinymce.xbl
[2] https://github.com/orbeon/orbeon-forms/blob/master/src/resources-packaged/xbl/orbeon/tinymce/tinymce.js

Alex

On Sat, Mar 31, 2012 at 6:21 AM, ncrofts <[hidden email]> wrote:

> Perhaps it may help if I clarify my aim. I'm actually trying to use XBL to
> wrap a media player control that is in the form of a javascript library. The
> URL of the media file must be constructed dynamically based on a value of
> another control (e.g xforms:input) also associated with the same data
> instance. Therefore the component interface will be of the form:
>
> <comp:player ref="instance('data')/name"/>
>
> where the value of the referenced instance data contains the name of a file
> which is then used to generate the final URL of the media file.
>
> The problem I'm having is knowing how to access this value from javascript
> within the XBL component. I can incorporate a script that is invoked when
> the referenced data instance value changes, but I just can't see how you can
> then access the value from javascript so that I can create the URL and pass
> it to the media control.
>
> <xxforms:script ev:event="xforms-value-changed" type="text/javascript">
>
>    /* How do you access the components referenced value? */
>    var controlValue = ORBEON.xforms.Document.getValue(??????????);
>
>    /* construct the url of the media file from this value. */
>    alert('VALUE: ' + controlValue);
>
> </xxforms:script>
>
>
> Can anybody suggest an appropriate way to solve this sort of problem in an
> Xforms XBL component?
>
> Regards,
> Neil
>
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/Accessing-value-of-bound-control-of-an-XBL-component-tp4503850p4521628.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>


--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Re: Accessing value of bound control of an XBL component

ncrofts
Hi Alex,

I will take a look at the tinymce sample and see how far I can get.

Thanks for the advice.

Regards,
Neil