On Wed, May 14, 2003 at 01:16:13PM +0200, Alexander Brill wrote: | I am trying to write my own validators following the examples that comes | with FormKit, but they always raise an exception - and I can't figure | out why (the example works). I also get the same exception at some of my | pages when using the validators that come with FormKit.
Alexander, FYI, FormKit isn't part of the Webware distribution, so I'm not sure that this list is quite the right place to ask. I'm one of the lead developers, so I can probably help you. I suppose that we should set up lists, too. Argh. | Here's the code for the validator I wrote: | class CompanyDoesNotExist(BaseValidatorClasses.FormValidator,SitePage): | """ Make sure a company doesn't exist before we add it """ | def validate(self,valueDict): | if self.compExists(valueDict['name']): | raise BaseValidatorClasses.InvalidField, "This company | already exists." | | def validatePartialForm(self): | return 1 | First, Are you sure that you want to use a form validator? A form validator is for when you need to access multiple fields to determine if the form as a whole is "valid". For example, you might require that two different fields each have the same string. Most of the time, you want to just validate one field; it /looks/ like that's what you're trying to do. In that case, you need to inherit from the "ValidatorConverter" class, as in the examples. Also, I'm not sure why you're attempting to inherit from both a validator and a servlet page; that can't possibly be good ;) In short, change your class definition to this: from BaseValidatorClasses import ValidatorConverter, InvalidField class CompanyDoesNotExist( ValidatorConverter ): """ Make sure a company doesn't exist before we add it """ def validate(self,valueDict): if self.compExists(valueDict['name']): return "This company already exists" else: return None Notice that I don't have to "raise" anything; the validator either returns None or something; if it's something, it's invalid. Good luck. ------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ Webware-discuss mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-discuss