Discussion:
Xforms Validation
Pierre Busnel
2004-05-27 12:20:30 UTC
Permalink
Hi,

I've been trying in vain to add constraints to a xforms. What I am trying to do is to make sure the user will enter an integer in a certain field. I found easy to test the length of a field or others things using Xpath functions, but I dont see how I can test the type or how I can use regular expressions.
In the code below, the user can enter a 2 characters string, even if the type is an integer. How can I prevent the user from entering anything else than numbers ?

Regards

Pierre Busnel

PS: By the way, I think Xforms is the "next big thing". Or I'll be damned to try to understand how it works for nothing !!

--- controls.xforms ---

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">

<head>
<link rel="stylesheet" type="text/css" href="xforms.css" />
<xforms:model xforms:id="model_0">
<xforms:instance xforms:id="instance_0">
<liste>
<champ1/>
</liste>
</xforms:instance>

<xforms:bind xforms:id="bind_1" nodeset="instance('instance_0')/champ1" type="xs:integer" constraint="string-length()=2" required="true()"/>

<xforms:submission action="http://192.168.9.12:8080/xform/app" method="post" id="submit" />
</xforms:model>
</head>
<body>

<xforms:input xforms:bind="bind_1">
<xforms:label>Champ 1</xforms:label>
</xforms:input>

<xforms:trigger>
<xforms:label>Submit</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:message ev:event="xforms-invalid" level="modal"> invalid field </xforms:message>
<xforms:send submission="submit"/>
</xforms:action>
</xforms:trigger>


</body>
</html>
Robert Bateman
2004-05-27 13:39:57 UTC
Permalink
Pierre,

I'm not an XForms expert.... But, I think I noticed a possible typo in your
code...

In

<xforms:bind xforms:id="bind_1" nodeset="instance('instance_0')/champ1"
type="xs:integer" constraint="string-length()=2" required="true()"/>

You are "typing" your bing to xs:integer But I don't see the XS name space
declared. Is it possible that should be xsd:integer?

I don't know if it makes a difference at the <instance> level, but my xforms
code has types in my instance variables as well (atleast those that are *not*
declared in a schema.)

Hope this helps!

Bob
Post by Pierre Busnel
Hi,
I've been trying in vain to add constraints to a xforms. What I am trying
to do is to make sure the user will enter an integer in a certain field. I
found easy to test the length of a field or others things using Xpath
functions, but I dont see how I can test the type or how I can use regular
expressions. In the code below, the user can enter a 2 characters string,
even if the type is an integer. How can I prevent the user from entering
anything else than numbers ?
Regards
Pierre Busnel
PS: By the way, I think Xforms is the "next big thing". Or I'll be damned
to try to understand how it works for nothing !!
Pierre Busnel
2004-05-28 07:14:59 UTC
Permalink
Well, I found out I could use the number() function to be sure the user enter an integer only, doing like this: <xforms:bind xforms:id="bind_2" nodeset="instance('instance_0')/champ2" type="xs:integer" constraint="number()&gt;0" required="true()"/>

On the others end, I tried adding the xs name space and didn't notice any change, but it make the Xforms more coherent.

I am still looking for a way to use regular expressions if you have any idea.

Thans for your replies
Best regards

Pierre
---
Pierre Busnel

--------- Original Message ---------

DATE: Thu, 27 May 2004 09:39:57
Post by Robert Bateman
Pierre,
I'm not an XForms expert.... But, I think I noticed a possible typo in your
code...
In
<xforms:bind xforms:id="bind_1" nodeset="instance('instance_0')/champ1"
type="xs:integer" constraint="string-length()=2" required="true()"/>
You are "typing" your bing to xs:integer But I don't see the XS name space
declared. Is it possible that should be xsd:integer?
I don't know if it makes a difference at the <instance> level, but my xforms
code has types in my instance variables as well (atleast those that are *not*
declared in a schema.)
Hope this helps!
Bob
Post by Pierre Busnel
Hi,
I've been trying in vain to add constraints to a xforms. What I am trying
to do is to make sure the user will enter an integer in a certain field. I
found easy to test the length of a field or others things using Xpath
functions, but I dont see how I can test the type or how I can use regular
expressions. In the code below, the user can enter a 2 characters string,
even if the type is an integer. How can I prevent the user from entering
anything else than numbers ?
Regards
Pierre Busnel
PS: By the way, I think Xforms is the "next big thing". Or I'll be damned
to try to understand how it works for nothing !!
Loading...