cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <>
Subject Re: <fd:validation><fd:javascript>
Date Thu, 27 Oct 2005 08:30:18 GMT
On Wed, 2005-10-26 at 13:31 -0400, Ben Anderson wrote:
> Hi,
> So I was trying to put javascript validation right into my form
> definition, but ran into some funkiness (at least from my
> perspective).
> First of all I realized that putting the javascript in a field doesn't
> "invalidate" the form:
> Here's my form definition:
>   <fd:validation>
>     <fd:javascript>
>       <fd:failmessage>failed on form</fd:failmessage>
>       cocoon.log.debug("form returning false");
>       return false;
>     </fd:javascript>
>   </fd:validation>
>   <fd:widgets>
>     <fd:field id="action">
>       <fd:label>action</fd:label>
>       <fd:datatype base="string"/>
>       <fd:validation>
>         <fd:javascript>
>           cocoon.log.debug("widget returning false");
>           return false;
>         </fd:javascript>
>       </fd:validation>
>     </fd:field>
> What's interesting is that both log messages are printed.  However, if
> I change the <fd:javascript> on the form to return true then
> widget.isValid() returns true even though my action field still
> returns false.  CForms online documentation for <fd:javascript> says
> to consult the examples in the source.  I only found one example and
> it is directly under the form (not the widget).
> Question #1: This leads me to believe that maybe I can't put
> <fd:javascript> under the <fd:field><fd:validation> element?
> Also, the <fd:failmessage> element was wishful thinking on my part
> which doesn't seem to do anything.  The xml of the form looks the same
> after the forms transformer whether I return true or false.  
> Question #2: Using <fd:javascript> for validation, is there a way to
> get messages printed out at all let alone something useful like this
> <fd:javascript>
>   if (!someDAO.getOrders().size() > 0) {
>     // send "must attach order" message
>   } else if (!someOtherDAO.isValidCustomer()) {
>     // send "must register first" message
> ...
> Maybe I'm just pushing the limits of the javascript validator... any
> ideas?

In the javascript validation (or in any validation for that matter), if
you return false, you should also set a validation error on the widget
to which the validator belongs, or a child/descendant widget of that
widget (e.g. in case the validator belongs to a form or repeater).

Have a look at the source of the samples for how to do this.

Bruno Dumon                   
Outerthought - Open Source, Java & XML Competence Support Center                

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message