[Zope3-Users] Re: Formlib - handleSubmit, custom validator on action

Darryl Cousins darryl at darrylcousins.net.nz
Thu Mar 29 09:11:08 EDT 2007


Hi,


On Thu, 2007-03-29 at 14:44 +0200, Philipp von Weitershausen wrote:
> Darryl Cousins wrote:
> > On Thu, 2007-03-29 at 05:52 -0400, Fred Drake wrote: 
> >> On 3/29/07, Darryl Cousins <darryl-dF9uhgPY3yxHRB3IUnr2w72Sh7SDDEB6 at public.gmane.org> wrote:
> >>> but the line previous says
> >>>
> >>>   data = {}
> >>>
> >>> So my validator always receives an empty dictionary to validate.
> >> The validator is responsible for populating `data` with the valid
> >> values.  That's definitely covered in the docs somewhere.
> >>
> >>
> >>   -Fred
> >>
> > 
> > Cheers for the reply Fred. Indeed form.txt in formlib does say:
> > 
> > """
> > If the validator is provided as a method name, the method  will be
> > called with the action and a dictionary in which to save data.
> > """
> > 
> > Then the assumption is that the custom validator method will get the
> > submitted values from the form object (also passed to the method along
> > with the action and `empty` dictionary, though that isn't mentioned in
> > form.txt). I'm thinking that the use-case for this functionality has
> > been lost in development; historical flotsam. Who, after all, needs an
> > empty dictionary passed to a method? And the method is expected to
> > return <quote form.txt> a (usually empty) list of widget input errors.
> > So what is the point of having an empty dict to populate?
> > 
> > `data` itself is not returned, nor available outside the method, so your
> > answer "with the valid values" makes little sense to me. But maybe I'm
> > missing something?
> 
> You are. The validator is not given just *any* empty dictionary, it is 
> given the data dictionary that will later be passed to the action.
> 
> 

OK. Then what I'm missing is how to assign a value to that variable
`data` because in my code

def my_validator(form, action, data):
	data = {'blah':'forgive me'}
	print data

>> {'blah':'forgive me'}

and a print statement in formlib/form.py directly after line 736:

        errors, action = handleSubmit(self.actions, data, self.validate)

	print data

>> {}

So I am always getting an empty dictionary back to my action method.

Sorry for the noise. In the meantime I've just gone back to creating an
interface with and @interface.invariant which is working for me. I was
just keen to find out if validator could be used.

Regards,
Darryl



More information about the Zope3-users mailing list