Karl Guertin wrote: > > AFAIK (and I've looked through most of the formencode codebase) there > is no way to definitively tell from a validator whether a field is > required or not without actually trying the to_python method with an > empty string. The not_empty attribute doesn't cover compound or custom > widgets. For example, I can use: > > validator = V.Any(V.Int,V.Empty) > > To make the validator field optional and not_empty won't appear on any > of the validators. >
Then this is a formencode bug, just like this: >>> test = v.NotEmpty() >>> test.not_empty False <--- O_o > > > I would expect it to work only by defining not_empty on my validator, > > it's DRY. > > I'm not so much a fan of DRY. It seems DRY tends to be synonymous with > 'magic happens'. If my field is required (and you will always need to specify it in your validator) the form should automatically use the field_required css class, where is the magic? I would expect it to be so, magic is something unexpected, but that's not the case. If this is magic then I should consider magic even my form displaying validation errors. :-) Ciao Michele

