You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Joerg Heinicke <jo...@gmx.de> on 2004/02/03 19:40:12 UTC
[CForms] xreporter assertion validation problem
It's a problem of "optionally required" as mentioned not only once on
the list. As a temporary solution I wanted to adapt Vadim's work around
[1] using assertion validation. Therefore I had a look into the
XReporter expression language [2] and wrote following form defintion.
<wd:field id="persontype">
<wd:datatype base="integer"/>
</wd:field>
<!-- NaturalPerson -->
<wd:field id="lastname">
<wd:label><i18n:text key="lastname"/></wd:label>
<wd:datatype base="string">
<wd:validation>
<wd:assert test="If(persontype = 0, Not(IsNull(lastname)), true)"/>
</wd:validation>
</wd:datatype>
</wd:field>
<wd:field id="firstname">
<wd:label><i18n:text key="firstname"/></wd:label>
<wd:datatype base="string">
<wd:validation>
<wd:assert test="If(persontype = 0, Not(IsNull(firstname)), true)"/>
</wd:validation>
</wd:datatype>
</wd:field>
<!-- LegalPerson -->
<wd:field id="name">
<wd:label><i18n:text key="name"/></wd:label>
<wd:datatype base="string">
<wd:validation>
<wd:assert test="If(persontype = 1, Not(IsNull(name)), true)"/>
</wd:validation>
</wd:datatype>
</wd:field>
<wd:field id="commercialRegisterNumber">
<wd:label><i18n:text key="commercialRegisterNumber"/></wd:label>
<wd:datatype base="string">
<wd:validation>
<wd:assert test="If(persontype = 1,
Not(IsNull(commercialRegisterNumber)), true)"/>
</wd:validation>
</wd:datatype>
</wd:field>
The validation should be clear IMO:
If persontype 0 is selected the lastname and the firstname must not be
null, otherwise return true.
If persontype 1 is selected the name and the commercialRegisterNumber
must not be null, otherwise return true.
This works if I sent a form with persontype = 1 and both the fields name
and commercialRegisterNumber not null. But if does not work if I switch
to persontype 0 with the fields lastname and firstname null. There the
validation for the fields name and commercialRegisterNumber fail though
they are not null! Seems to be somewhat strang IMO.
Does anybody see an obvious mistake or know why?
Joerg
[1] http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=107352171910636&w=4
[2] http://xreporter.cocoondev.org/en/expressions.html
Re: [CForms] xreporter assertion validation problem
Posted by Joerg Heinicke <jo...@gmx.de>.
Hello Bruno,
On 03.02.2004 19:54, Bruno Dumon wrote:
>> <wd:validation>
>> <wd:assert test="If(persontype = 0, Not(IsNull(lastname)), true)"/>
>> </wd:validation>
>
> The expression language doesn't have a predefined true constant, instead
> 'true' here means a variable named true which likely doesn't exist,
> unless you would happen to have a widget with id 'true'.
>
> Instead, use the True() function.
replacing true with True() my tests do never fail now. Neither the
change to the Or() based test like Vadim's test nor simply just
"Not(IsNull(lastname))" return the expected false. Is there a verbose
mode available anywhere for debugging what's going on?
Joerg
Re: [CForms] xreporter assertion validation problem
Posted by Joerg Heinicke <jo...@gmx.de>.
Hello Bruno,
On 03.02.2004 19:54, Bruno Dumon wrote:
>> <wd:validation>
>> <wd:assert test="If(persontype = 0, Not(IsNull(lastname)), true)"/>
>> </wd:validation>
>
> The expression language doesn't have a predefined true constant, instead
> 'true' here means a variable named true which likely doesn't exist,
> unless you would happen to have a widget with id 'true'.
>
> Instead, use the True() function.
it was indeed naive to assume a constant 'true' - especially as the
True() function is not mentioned far away from Or() or If() at
http://xreporter.cocoondev.org/en/expressions.html.
Thanks,
Joerg
Re: [CForms] xreporter assertion validation problem
Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2004-02-03 at 19:40, Joerg Heinicke wrote:
<snip/>
> <wd:validation>
> <wd:assert test="If(persontype = 0, Not(IsNull(lastname)), true)"/>
> </wd:validation>
The expression language doesn't have a predefined true constant, instead
'true' here means a variable named true which likely doesn't exist,
unless you would happen to have a widget with id 'true'.
Instead, use the True() function.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org