cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: Cocoon Forms 2.1 - One of two fields required
Date Wed, 25 Feb 2009 13:21:07 GMT
> In Cocoon 2.1, Forms, how do I require the user to fill at least one  
> out of two (or more) fields?
> For example, I might have the 'phone' and 'mobile' fields. I 
> want the  
> user to fill at least one of them, possibly both, and I don't 
> want the  
> form to validate if they're both empty.
> I've tried to add the validator to one or the other, but it 
> seems the  
> wrong place to put it (Cocoon forms have a strict hierarchical  
> structure) and in fact the behaviour with ajax and browser-update is  
> buggy.  I've tried to add the validator to the form widget 
> itself, but  
> then the error message is not picked up by the jx template, and the  
> user is stuck without knowing what is wrong.
> Where should I put such a validator?
> Tobia


you can put the general form validation code straight into the form element:

<fd:form xmlns:fd="">
      <!-- form validation code -->
      var error = null;
      var widget1 = widget.lookupWidget("field1");
      var value1 = widget1.getValue();		

      if (anythingWrongForASingleWidget)

      if (error == null)
        return true;
      return false;

    <fd:field id="field1">
        <!-- field valdation -->

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

View raw message