On Apr 2, 2007, at 3:04 AM, George Sakkis wrote:
> > I wasted the best part of the day trying to figure out why a > particular form doesn't display the values as it should. It eventually > came down to the fact that the validator=some_schema parameter of form > doesn't work as advertised (or at all) at > http://docs.turbogears.org/1.0/RoughDocs/FormValidationWithSchemas. > Here's a minimal cut-down version: > > Without schema - works: > ================== > class MyFields(WidgetsList): > name = TextField(validator=validators.Wrapper( > from_python=lambda value: raiseNameErrorHere)) > return TableForm(fields=MyFields()) > > t1 = TableForm(fields=FunctionFields()) > # the next line throws NameError as it should > t1.display(value={'name':'foo'}) > > With schema - doesn't work > ===================== > class MySchema(validators.Schema): > name = validators.Wrapper(from_python=lambda value: > raiseNameErrorHere) > > class FunctionFields(WidgetsList): > name = TextField() > > t2 = TableForm(validator=FunctionSchema(), fields=FunctionFields()) > # this doesn't call the from_python() on name's validator > t2.display(value={'name':'foo'}) > > Is this a known bug or should I open a ticket ? widgets adjust their value with the widget's adjust_value method. from_python is never called in CompoundWidgets because it's Schema's from_python will call all sub-validators' from_pythons recursively which causes problems since child widgets expect a python value in update_params or else strange things happen. Hence, only the first version works. If you need to adjust the value sent to the template in a CompoundWidget your best bet is to override its adjust_value method and do it there, make sure its class attribute "convert" is True or else adjust value won't be called at all. You can also pass this parameter to "display" to override the default. Docs should probably be updated to reflect this, anyone? :) Alberto --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

