[z3-five] formlib yes or no

Kapil Thangavelu k_vertigo at objectrealms.net
Thu Dec 7 20:27:18 CET 2006


On Thu, 07 Dec 2006 12:34:30 -0500, Dennis Schulz <d.schulz81 at gmx.net>  
wrote:

> Hello
>
> I am currently in a decision making process to build an application.
> (actually already over it)
> In the last weeks and even months I made experiences with formlib and I
> am questioning if it makes sense to carry on with formlib or design
> everything from the ground up manually in own page templates.
> The most scary thing is that there is very few documentation and almost
> no examples of bigger applications using it.
> Is anybody else using formlib/ widgets/ objectwidgets?
> This is my first bigger application in which I try to use it, but I am
> getting into more and more issues and thinking of swiching to handmade
> forms again.
> Maybe when it gets too special and there has to be customized to much in
> comparision to the autogenerated form it is not worth dealing with all
> the problems you get.
>

i've been using formlib extensively the last few months, it definitely has  
a few warts as regards z2, but just most of the issues can be solved with  
a custom subclass or custom widget. what formlib gives in turn offers  
enough benefits that i tend to think its a huge win over manually dealing  
with form validation/actions and is fairly generic as a policy framework  
for attaching validation/failure/success handlers to, but i agree, that  
its at times convoluted. and there is a strong sense when using that  
widget framework hasn't been used in 'anger' in z2, thats distinct from  
formlib though.

> Here a list of problems I currently have that are at least closly
> related to formlib:
>
> - there is no update of no-value on select fields (choice). normally you
> should also be able to choose nothing when the field is required=False

probably easiest to just register a custom select field widget, that has a  
blank option whhere warranted.

> - Standard AddFormbase is only for input widgets. I made an alternative
> version that also allows passing the value through displayWidgets like
> in the editForm.
> Here I had the strange problem, that one particular value was sometimes
> not included when for_display=True, but maybe also my own fault.
>

dunno.

> - What is the best place to set fields with default values? Sometimes I
> need to get these values with GET. overwrite setupWidgets and set the
> get_rendered attribute of the fields?
>

formlib sometimes needs some help here, you can either initialize the  
object context with field defaults prior to display, manually constructing  
formfield iterating over schema.getFields( iface ) to pass to a fields  
container with get_rendered set (get_rendered = lambda form, field=field,  
field.default), or subclass form and reimplement setupWidgets, i had to  
custom patch it to get this, afaicr...


> - various action buttons that allow a different application of the
> entered values. How only validating a certain part of the form?

you can set a different validator on a given action, which can implement  
validation however you want.


>
> - cancel button without any validation? In my form every click on cancel
> also performs a validation even if I don't explicitly call applychanges.
> Why?


hmm.. this is sort of lame.. i agree, the formbase.validate always gets  
called..

form.formbase.update->form.handleSubmit->(no custom validator on  
action)->default validator->formbase.validate

you can define a return true validator on your cancel action to avoid, or  
override update.


>
> - more control over validation. how can I validate and save only two
> fields of a form, not the whole list?


custom validator on action, custom success handler on action.


hth,

kapil


More information about the z3-five mailing list