Hi Alberto,
Alberto Valverde wrote:
> ...
>
> I see your problem here when trying to set the is_required flag, but
> maybe you could make the Form take care of it like it already does
> for errors as the form *knows* all it's subvalidators *effective*
> validators when built.
>
I don't have a problem with the is_required flag, I've got it working
by just using the path (any revision before r980 IIRC), that's not a
big deal really. ;-)
The real problem is that having a flying validator means that there is
no way a widget can trust self.validator as being correct, this means
we can just remove it at this point, a widget will never be sure at
100% of self.validator as being right hence it should not use it, not
in adjust_value not in any other way.
To make a real example (as you've made), a SelectionField widget
requires a trusted validator to use, this example will not work in any
way:
class MySchema(Schema):
options = String()
class MyFields(...):
options = SingleSelectionField(options=[(1, "Java"), (2,
"Python")], validator=Int())
form = TableForm(fields=MyFields(), validator=MySchema())
since you changed the validator you will change options, if you the use
something like:
options = [('One', 'Hello'), ('Two', 'ByeBye')]
the widget will not maintain values on form redisplay since it's using
the Int() validator and not the String() one.
I know this is a dumb example but it's something that could happen if
you're doing the same thing with the validator this is identical.
> This would probably solve it. The bottom line is that containers
> *should not* modify in any way their child widgets. If this simple
> rule is kept then instances can be freely reused because they're
> totally agnostic of their container.
>
I'm ok with this rule as Kevin said, I do think reusing widget instance
is a good goal we should support, my only grip is the one I described.
Another way to solve it and reusing widgets instance could be this:
- validator is used only for InputWidgets (it makes sense IMHO)
- we find a way to make self.validator a property that can use the path
(since an InputWiget has it) to retrieve on the fly it's validator from
the root widget (has I've done with is_required).
this also makes sense since it's true that you could need the to/from
python work of a validator even for widget that aren't form fields like
an AjaxGrid, but you don't need the to_python thing (no input coming)
and for the from_python what you want is just the conversion to a
string (everything is a string on the web) or some other fancy feature
that you can easily do inside update_data without the need to learn how
to use FancyValidator.
If someone has a solution to make (self.validator) a property that
doesn't end-up in a infinite recursion and is good with avoiding the
use of validator for widgets not related to input (this makes a lot of
sense IMHO and will again simplify things a lot for the use of widgets
outside of a form) we can use that and all problems are solved. ;-)
Ciao
Michele
PS
I'm going to revert this thing in one minute... ;-)
And I will try to show how we can solve this in the way I described (I
have an idea to avoid the infinite recursion).
> Alberto,
>
> BTW: Nice job with the Repeating :) haven't tested it yet but looks
> good.... It seems I can't go offline for more than 3 days without
> missing a lot... :D
LOL :-) I missed you... :P
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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-trunk
-~----------~----~----~----~------~----~------~--~---