cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Wolfgang.Ruelf...@it.nrw.de>
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


Hello,

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

<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
  <fd:validation>
    <fd:javascript>
      <!-- form validation code -->
      var error = null;
      var widget1 = widget.lookupWidget("field1");
      var value1 = widget1.getValue();		
      //...

      if (anythingWrongForASingleWidget)
        widget1.setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("errorMessage",
false));

      if (error == null)
        return true;
      return false;
    </fd:javascript>
  </fd:validation>

  <fd:widgets>
    <fd:field id="field1">
      <fd:validation>
        <!-- field valdation -->
          </fd:validation>
    </fd:field>
  </fd:widgets>
</fd:form>


regards,
Wolfgang
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message