Jason Chu wrote:
> >
> > This is at display time, correct? (Not validation time...) There
> > didn't used to be a way to do this, did there?
>
> At this point, I've been thinking about display time. It would be
> needed for validation time as well. All CompoundWidgets would have
> this problem.
>
At validation time all the values are passed to the validate method so
the field is responsible for validating itself using the right value
associated:
def validate(self, values):
if self.validator:
values[self.name] = self.validator.to_python(
values.get(self.name, None))
You can try the FieldSet widget and you will see that validation works.
The real problem is only with values (and not input values that are
already managed by every field itself by using
cherrypy.request.input_values) provided at display time or as default
value.
A possible solution could be to use on CompoundWidgets a method that
return a list of it's children widgets names, in this way we can fix
the Form widget so that for compound widgets it calls the display
method with a value that's a dict with the right name/value pair, will
this work?
an example by modifying the actual form:
if field.name not in disabled_fields:
if not field.compound:
field_value = getattr(values, field.name, None)
else:
field_value = {}
for name in field.children_names():
field_value[name] = getattr(values, name, None)
Not tested but it should work I guess, children_names is a horrible
name by the way (a read-only property is also best suited I think).
Ciao
Michele
[I posted a message like this before but it doesn't show up, sorry if a
duplicated something]