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?
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
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.
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?
--
Colin Paul Adams
Preston Lancashire
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]