> > 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: [email protected] For additional commands, e-mail: [email protected]
