Orbeon and javascript [SEC=UNCLASSIFIED]

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

Orbeon and javascript [SEC=UNCLASSIFIED]

sarah.wojtaszak

Hi All


Has anyone managed to use javascript within their orbeon XForm to validate (via prevention) user input?


The solution i'm looking for is to prevent users from typing an alpha character in a numeric field.  Preferably we'd like javascript (keypress event) to stop any character other than 1-9 from being displayed in the field.


Our only solution at this stage is to use the xforms-value-changed event to remove any alpha characters from the input field.  This is not ideal as it changes the input without the users knowing it.

The 'age' field example in the orbeon sandbox, uses validation to tell the user that they have provided invalid input, but it doesn't stop a user from entering an age of 'three'.


Thanks.
Sarah.

------------------------------------------------------------------------------------------------

NatStats 2010 Conference, 15-17 September 2010, Sydney. For more information visit www.nss.gov.au/natstats2010



--
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
Reply | Threaded
Open this post in threaded view
|

Re: Orbeon and javascript [SEC=UNCLASSIFIED]

Alessandro  Vernet
Administrator
Hi Sarah,

Certainly, you can register your own listener. Like you said, if you
can do it with XForms events, it is better to go that route, but in
this case you'd like to catch some keys before they are even displayed
by the input field, so JavaScript is the way to go. In essence,
something as follows should do the trick:

    <xforms:input ref=".">
        <xxforms:script ev:event="xforms-enabled">
            var input = ORBEON.util.Dom.getElementByTagName(this, "input");
            YAHOO.util.Event.addListener(input, "keydown", function(event) {
                // Do something with event.keyCode
            });
        </xxforms:script>
    </xforms:input>

Alex

On Wed, May 5, 2010 at 5:35 PM, Sarah Wojtaszak
<[hidden email]> wrote:

>
> Hi All
>
>
> Has anyone managed to use javascript within their orbeon XForm to validate
> (via prevention) user input?
>
>
> The solution i'm looking for is to prevent users from typing an alpha
> character in a numeric field.  Preferably we'd like javascript (keypress
> event) to stop any character other than 1-9 from being displayed in the
> field.
>
>
> Our only solution at this stage is to use the xforms-value-changed event to
> remove any alpha characters from the input field.  This is not ideal as it
> changes the input without the users knowing it.
>
> The 'age' field example in the orbeon sandbox, uses validation to tell the
> user that they have provided invalid input, but it doesn't stop a user from
> entering an age of 'three'.
>
>
> Thanks.
> Sarah.
>
> ------------------------------------------------------------------------------------------------
>
> NatStats 2010 Conference, 15-17 September 2010, Sydney. For more information
> visit www.nss.gov.au/natstats2010
>
> --
> 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
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/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