constraint in xforms:bind when value is empty

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

constraint in xforms:bind when value is empty

Jency Thomas

Hi,

 

I have an issue with xforms:bind. I need to do an xforms:bind giving its type as well as a constraint. My requirement is that the constraint should be evaluated only if there is some value in the input.

For eg: I have 2 binds as :

 

<xforms:bind nodeset="instance('INSTANCE')/DOB/DD" type="xforms:integer" constraint=". castable as xs:integer and .&gt;=1 and 31&gt;=."></xforms:bind>

<xforms:bind nodeset="instance('INSTANCE')/InsPeriod/YYYY" type="xforms:string" constraint="string-length(.)&gt;=4 and 4&gt;=string-length(.) "></xforms:bind>

 

In both cases, when the form is first loaded, it shows exclamation mark indicating validation error. My requirement is that these fields should be validated only if there is some value in it. How can I achieve this?

Please help. This is urgent.

 

Thanks in advance

Jency

 

        

 



--
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: constraint in xforms:bind when value is empty

fl.schmitt(ops-users)
Hi Jency,

> <xforms:bind nodeset="instance('INSTANCE')/DOB/DD"
> type="xforms:integer" constraint=". castable as xs:integer and
> .&gt;=1 and 31&gt;=."></xforms:bind>

> <xforms:bind nodeset="instance('INSTANCE')/InsPeriod/YYYY"
> type="xforms:string" constraint="string-length(.)&gt;=4 and
> 4&gt;=string-length(.) "></xforms:bind>

> In both cases, when the form is first loaded, it shows exclamation
> mark indicating validation error. My requirement is that these fields
> should be validated only if there is some value in it. How can I
> achieve this?

A quick (may not the best) solution could be to rewrite the constraint
clause using a if statement. If the element content is '', then the
constraint is true(), else the test you already wrote should be relevant:

<xforms:bind
     nodeset="instance('INSTANCE')/DOB/DD"
     type="xforms:integer"
     constraint="if (. eq '')
         then true()
         else
             (. castable as xs:integer and .&gt;=1 and 31&gt;=.)"
/>

HTH
florian



--
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: Re: constraint in xforms:bind when value is empty

Jency Thomas
Thanks Florian. It works

-----Original Message-----
From: Florian Schmitt [mailto:[hidden email]]
Sent: Monday, April 28, 2008 4:40 PM
To: [hidden email]
Subject: [ops-users] Re: constraint in xforms:bind when value is empty

Hi Jency,

> <xforms:bind nodeset="instance('INSTANCE')/DOB/DD"
> type="xforms:integer" constraint=". castable as xs:integer and
> .&gt;=1 and 31&gt;=."></xforms:bind>

> <xforms:bind nodeset="instance('INSTANCE')/InsPeriod/YYYY"
> type="xforms:string" constraint="string-length(.)&gt;=4 and
> 4&gt;=string-length(.) "></xforms:bind>

> In both cases, when the form is first loaded, it shows exclamation
> mark indicating validation error. My requirement is that these fields
> should be validated only if there is some value in it. How can I
> achieve this?

A quick (may not the best) solution could be to rewrite the constraint
clause using a if statement. If the element content is '', then the
constraint is true(), else the test you already wrote should be
relevant:

<xforms:bind
     nodeset="instance('INSTANCE')/DOB/DD"
     type="xforms:integer"
     constraint="if (. eq '')
         then true()
         else
             (. castable as xs:integer and .&gt;=1 and 31&gt;=.)"
/>

HTH
florian



--
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