[Cubicweb] Custom form validation

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Feb 17 08:28:15 CET 2010

On 16 février 17:03, Sandrine Ribeau wrote:
> Hi,

> I would like to validate a form so that a validation error will be raised if 
> none of the three 'important' attributes are provided. So far no attribute is 
> required on my entity since we want to allow the user to either provide attr1, 
> attr2 or attr3. User needs only to provide on out of the three bu can provide 
> the three attributes.
> Should I write a specific JSONController for this entity type? Or is there a 
> better way to do it?

usually, proper validation in cw should be done on the repository side, so you're
sure that whatever the way used to add data, they're correctly validated (eg, not
only through the web ui). So, you should write a small after_add_entity / 
after_update_entity hook that raise proper validation error when conditions are 
not met.

Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org

More information about the Cubicweb mailing list