Making not_empty depend on other fields
"Paul Johnston" <[email protected]>
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Hi, I have a form, on which some fields may be optional or compulsory, depending on the value of a different field. I'm using FormEncode, ToscaWidgets and TurboGears. I have a hacky solution, looking for a neater one. I realise I could use a compound validator, but this won't give me the error reporting I want. I'd like the "please enter a value" message to appear next to the fields. Using a compound validator would put a message like "department: please enter a value" at the bottom of the form. The current solution I have is: schema.py is modified so if the field "invtype" is present, it is processed first. the validator for invtype sets some information on cherrypy.request about what fields will be compulsory. the validators for switchable compulsory/optional fields have not_empty set to a property, which looks at cherrypy.request The main problem is that this needs modifications to FormEncode. I did try using pre_validators to force that field to go first, but it didn't work - no exception, I just ended up getting no data or errors from the validator. If someone can suggest another way to do this, that would be great! Also, I couldn't use FormEncode's state mechanism, I think because ToscaWidgets breaks up the validation. Using cherrypy.request seems a bit hacky, but works fine really. Any suggestions would be welcome, Paul ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ FormEncode-discuss mailing list FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/formencode-discuss