Re: [Zope3-Users] Re: formlib vs. cancel button
On Thu, Feb 15, 2007 at 09:55:19AM +, Martin Aspeli wrote: Dennis Schulz wrote: I dont know if it is the proper way, but when I return an empty string there is no validation error. This was also one of the strangest things I found out with formlib. I found that returning {} also works. The validator is supposed to return a list of errors. Neither '' nor {} are lists. () is a list. I use @form.action(Cancel, validator=lambda *a: ()) def cancel(self, action, data): ... But this is clearly a design weakness if there is no other way of doing it. Something like validator=NULL_VALIDATOR would be fine, or some kind of decorator. +1 for allowing @form.action(Cancel, validator=form.no_validation) Note that as a side effect of an empty validator you will always get an empty data dictionary in the handler method. Marius Gedminas -- Corsac yeah, i'm reading the answers, currently Corsac but what I see is that there is no real procedure to rebuild initfs Corsac the common way seems to use a loop device with a jffs2 filesystem, put original files there, and add other files, then umount, flash and pray dwd Corsac: You forgot ritual sacrifice of a medium sized rodent. Without that, it'll never work. zuh And if it doesn't work the first time, re-adjust towel ordering in the restroom and try again -- #maemo signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: formlib vs. cancel button
On Thu, Feb 15, 2007 at 05:37:52PM +0100, Philipp von Weitershausen wrote: Martin Aspeli wrote: Marius Gedminas wrote: On Thu, Feb 15, 2007 at 09:55:19AM +, Martin Aspeli wrote: Dennis Schulz wrote: I dont know if it is the proper way, but when I return an empty string there is no validation error. This was also one of the strangest things I found out with formlib. I found that returning {} also works. The validator is supposed to return a list of errors. Neither '' nor {} are lists. () is a list. I use @form.action(Cancel, validator=lambda *a: ()) def cancel(self, action, data): ... But this is clearly a design weakness if there is no other way of doing it. Something like validator=NULL_VALIDATOR would be fine, or some kind of decorator. +1 for allowing @form.action(Cancel, validator=form.no_validation) I added something similar to plone.app.form, but there really, really should be support for this use case in formlib in a non-hacky way. We happily accept patches through collector entries. Actually, aren't you a committer? :) I'd be happy to implement and commit something, but I'd be happier if someone else designed the API. When I try to design APIs myself, I tend to change my mind too often. Now I want @form.action(Cancel, validator=None) to mean do no validation. But perhaps that's not backwards-compatible enough? Marius Gedminas -- The *REAL* Y2K is the year 2048. signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: formlib vs. cancel button
@form.action(Cancel, validator=None) -1 from me Currently above code is same as: @form.action(Cancel) So I think this is a very common pattern that means: do standard validation, do not use additional action validator. In general there are two validators. Action validator (one we are assigning in the above code) and default validator of the form. handleSubmit is responsible for handling action submits and this looks like that: def handleSubmit(actions, data, default_validate=None): for action in actions: if action.submitted(): errors = action.validate(data) # validator we want set to # None is used here if errors is None: errors = default_validate(action, data) return errors, action So first action.validate is called: def validate(self, data): if self.validator is not None: # THIS MAY BE NONE return self.validator(self.form, self, data) and when there are no errors (None is returned) then default validator is executed which is: def validate(self, action, data): return (getWidgetsData(self.widgets, self.prefix, data) + checkInvariants(self.form_fields, data)) I might be wrong somewhere, so somebody better check this :) -- Maciej Wisniowski ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: formlib vs. cancel button
Yes. I think you misunderstand my suggestion. I knew someone will write this :) I didn't think about default validator value before sending my previous email. I found this pattern after later... at bed :) so I agree that this might be a good solution that has enough backward compatibility and seems to be rather easy to implement +1 -- Maciej Wisniowski ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users