W3C home > Mailing lists > Public > www-forms@w3.org > January 2007

Re: setting xforms control value with javascript

From: Iņaki Salinas Bueno <inksalinas@gmail.com>
Date: Thu, 18 Jan 2007 19:54:49 +0100
Message-ID: <cd3c31800701181054q697d70ady9207a2252143ee2@mail.gmail.com>
To: mark.birbeck@x-port.net
Cc: "Dustin Whitney" <dustin.whitney@gmail.com>, www-forms <www-forms@w3.org>
Mark,

It would be interesting to do only with xforms, avoiding the use of
javascipt, but I have no idea of using extended function.

I tried anyway, and it doesn't work. I use Mozilla 2.0.0.1 with the last
extension of Mozilla XForms, but I don't have any way to know if it doesn't
work due to the processor or because the code is bad writing.

The problem will be due to this last one surely, but while these extended
functions are not more based I think that I choose the option of putting the
Javascript code in the XForms/XHTML document, although is ugly.

I let the test code I have used, maybe the failure was evident.

Thanks to show me this alternative!

Iņaki


2007/1/17, Mark Birbeck <mark.birbeck@x-port.net>:
>
> Iņaki,
>
> It's still a big hack though! :)
>
> In XForms, the load action has absolutely nothing to do with the
> executing of JavaScript functions, and I really hope that this
> technique doesn't catch on. XForms takes great pains to build nicely
> on top of XPath, and the way to achieve what you want is to create an
> extension function, and then just write this:
>
>   <xf:setvalue bind="docPKCS7" value="crypto:signText(somenode)" />
>
> That way you let the XForms model take care of everything, and you
> only need to worry about writing your extension function.
>
> Obviously, the specifics of adding extension functions will depend on
> which XForms processor you are using, but I'm pretty sure that most
> can do it now.
>
> Regards,
>
> Mark
>
> On 17/01/07, Iņaki Salinas Bueno <inksalinas@gmail.com> wrote:
> > Thanks Dustin!!
> >
> > Finally it works! I had nonsense problems with the namespaces, but I
> have
> > seen that it is not necessary to introduce them in the Javascript
> > getElementsByTagName function.
> >
> > Greetings
> > Iņaki
> >
> >
> > 2007/1/16, Dustin Whitney < dustin.whitney@gmail.com>:
> > >
> > > Heh, I was working on the same thing yesterday.  Here is a simple
> version
> > of what I accomplished, and probably what you are looking for.
> > >
> > > <html
> > >     xmlns="http://www.w3.org/1999/xhtml "
> > >     xmlns:xforms=" http://www.w3.org/2002/xforms"
> > >     xmlns:event="http://www.w3.org/2001/xml-events">
> > >     <head>
> > >         <script language="javascript">
> > >         <![CDATA[
> > >             function changeMe(){
> > >                 var model = document.getElementById("myModel");
> > >                  var instance = model.getInstanceDocument
> ("myInstance");
> > >                  var textElements = instance.getElementsByTagName
> ("text");
> > >                  textElements[0].firstChild.nodeValue =
> > 'Changed!';
> > >                 model.rebuild();
> > >                 model.refresh();
> > >             }
> > >         ]]>
> > >         </script>
> > >         <xforms:model id="myModel">
> > >             <xforms:instance id="myInstance">
> > >                 <text xmlns="">Change Me!</text>
> > >             </xforms:instance>
> > >             <xforms:instance id="script">
> > >                 <script url="javascript:changeMe()"/>
> > >             </xforms:instance>
> > >         </xforms:model>
> > >     </head>
> > >     <body>
> > >         <xforms:input ref="/text"/>
> > >         <xforms:trigger>
> > >             <xforms:label>Change!</xforms:label>
> > >             <xforms:load resource="javascript:changeMe()"
> > event:event="DOMActivate"/>
> > >         </xforms:trigger>
> > >     </body>
> > > </html>
> > >
> > > -Dustin
> > >
> > >
> > >
> > >
> > > On 1/16/07, Iņaki Salinas Bueno < inksalinas@gmail.com> wrote:
> > >
> > > > Hello,
> > > >
> > > > I'm trying to set the value of an xforms control using JavaScript: I
> > must use a JavaScript function, and set the result in the form.
> > > >
> > > > I call the Javascript function following a tip of Nicholase Chase
> from
> > IBM (using 'load'), and it works.
> > > >
> > > > I want to use this function:
> > > >
> > > >       document.getElementById('docPKCS7').value = crypto.signText
> > (document.getElementById('formulari').innerHTML, "auto");
> > > >
> > > > 'docPKCS7' must point to xforms control. The right part of the
> equality
> > works, but the allocation of the value obtained to the object pointed by
> > 'docPKCS7' not.
> > > >
> > > > This is the code of the xforms control:
> > > > <xforms:textarea bind="docPKCS7">
> > > >
> > > > I tried this too:
> > > > <xforms:textarea
> > ref="instance('auxiliars')/aux:ajudes/aux:solicitutPKCS7"
> > id="docPKCS7">
> > > >
> > > > And, following some advices from this post , I introduce the
> xhtml:id
> > attribute:
> > > > <xforms:textarea
> > ref="instance('auxiliars')/aux:ajudes/aux:solicitutPKCS7"
> > xhtml:id="docPKCS7">
> > > >
> > > > But nothing works. The javascript console don't show any problem or
> > warning, except using xhtml:id that appears the following:
> > > > Error: document.getElementById("docPKCS7") has no properties
> > > >
> > > > However, the problem is the allocation of the value in the xforms
> > control because using a HTML textarea it works (the value returned by
> the
> > function appears in the textarea):
> > > > <textarea id="docPKCS7" rows="5" cols="50"/>
> > > >
> > > > Maybe my problem is related to a namespace conflict (like this), but
> in
> > that case I don't know how to attack it.
> > > >
> > > > Where is the problem? What other things I can test?
> > > > Lot of thanks
> > > >
> > > > Iņaki
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
> --
> Mark Birbeck
> CEO
> x-port.net Ltd.
>
> e: Mark.Birbeck@x-port.net
> t: +44 (0) 20 7689 9232
> w: http://www.formsPlayer.com/
> b: http://internet-apps.blogspot.com/
>
> Download our XForms processor from
> http://www.formsPlayer.com/
>



Received on Thursday, 18 January 2007 18:55:00 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:08 GMT