On Sat, 2004-07-03 at 19:28, Colin Paul Adams wrote:
> I wish to perform cross-field validation on my form.
> 
> Specifically, with these two field definitions:
> 
>         <fd:field id="start-time">
>           <fd:label>Start time</fd:label>
>         <fd:hint>Start time for event</fd:hint>
>         <fd:help>Type in the time when the event starts (if you know it) as 
> hh:mm.</fd:help>
>           <fd:datatype base="date">
>           <fd:convertor datatype="date" variant="time" type="formatting">
>             <fd:patterns>
>               <fd:pattern>kk:mm</fd:pattern>
>             </fd:patterns>
>           </fd:convertor>
>         </fd:datatype>
>         </fd:field>
>         <fd:field id="finish-time">
>           <fd:label>Finish time</fd:label>
>         <fd:hint>Finish time for event</fd:hint>
>         <fd:help>Type in the time when the event finishes (if you know it) as hh:mm. 
> This is only permitted when a start time is supplied.</fd:help>
>           <fd:datatype base="date">
>           <fd:convertor datatype="date" variant="time" type="formatting">
>             <fd:patterns>
>               <fd:pattern>kk:mm</fd:pattern>
>             </fd:patterns>
>           </fd:convertor>
>           <fd:validation>
>             <fd:javascript>
>               var success = true;
>               var start_time = widget.lookupWidget("start-time");
>               if (start_time.value.length = 0) {
>               widget.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError("Start-time must be 
> specified along with finish-time", false));
>               success = false;
>               }
>       
>               // Must return true/false
>               return success;
>             </fd:javascript>
>           </fd:validation>
>         </fd:datatype>
>         </fd:field>
> 
> Then I want to write code to give an error message if the finish-time
> field is non-empty, but the start-time field is empty.
> 
> Questions:
> 
> 1) Is the converter also checked, and does it get called before or
>    after the fd:javascript?

The convertor is always the first thing, as the validation works on the
converted value. If the conversion fails, further validation on that
field isn't performed.

Conversion happens (or at least should happen -- current implementation
may be a bit different) during the "read from request" stage. That is,
first all widgets read their value, and for field widgets, convert it to
the datatype of the field. Then in a second stage validation is done, so
that validation rules can compare the converted values of different
fields.

> 2) The above doesn't work - I get an error:
> 
> "resource://org/apache/cocoon/forms/flow/javascript/Form.js", line 50:
> uncaught JavaScript exception: at handleForm
> (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line 249)
> at Form (resource://org/apache/cocoon/forms/flow/javascript/Form.js,
> Line 50): org.apache.avalon.framework.CascadingException: Unknown
> validation rule "javascript" specified at
> file:/home/colin/onevoice/members/forms/event-form.xml:47:23

This is probably because your fd:validation is inside your fd:datatype
(where did you find that? I thought all examples and docs were updated)

> 
> 
> org.apache.avalon.framework.CascadingRuntimeException: 
> "resource://org/apache/cocoon/forms/flow/javascript/Form.js", line 50: uncaught 
> JavaScript exception: at handleForm 
> (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line 249) at Form 
> (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line 50): 
> org.apache.avalon.framework.CascadingException: Unknown validation rule "javascript" 
> specified at file:/home/colin/onevoice/members/forms/event-form.xml:47:23
> 
> 
> cause: org.apache.avalon.framework.service.ServiceException: Non-existing component 
> for this hint (Key='javascript') 
> 
> The documentation (2.1.5) doesn't mention which elements allow
> fd:javascript as a validator.

all

> 
> Looking in the examples, I see it used for fd:repeater, fd:form and
> fd:on-create.
> Is it truly disallowed for fd:field, or is it the datatype of date
> that is causing the problem?
> 
> Also, is the code line:
>  var start_time = widget.lookupWidget("start-time");
> a correct way to access the start-time field?

this will lookup a child widget named start-time, and a field widget
can't have child widgets. I think you can do
widget.lookupWidget("../start-time") or else
widget.getForm().getChild("start-time").

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
[EMAIL PROTECTED]                          [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to