Hi Max,
thanks for the feedback.
I'm also convinced that the former solution is much easier, the problem
is that I don't really want TG widgets to get into your way of doing
things, the TG philosophy (as I've got it at least) is to not hide some
of the components we use, in this case FormEncode, and from some
blog/feedback I've read this gives a nice feeling.
In other words I wouldn't want widgets to to magic things on the
validation side, like the is_required parameter that acts on the
not_empty attribute.
I mean this is easier:
TextField(is_required=True)
but this is more explicit of what's going on, doesn't hide FE and
follows the Widget philosophy or reusing FE and it's feature (not only
a simple validator but also a Schema).
TextField(validator=NotEmpty())
the solution I'm proposing is needed for such widget that already
provide a default validator (SelectionField, FileField in the future)
and when you would like to tweak some parameters without redefining the
entire validator:
MultipleSelectionField(validators_args={'not_empty':True})
two points:
1) the syntax is pretty self explanatory of what will happen since
validator_args is clearly bounded to the validator being used
2) the syntax is also flexible since you can also define additional
parameters and not only not_empty but for example also the error
message
Again any opinions and reply is welcome, I wouldn't have go down this
path in another case but the former solution was suddenly looking not
so clear to me (and I'm the one implementing it) so I can imagine what
will happens with users and explaining something going wrong for this
reason.
Ciao
Michele
Max Ischenko wrote:
>
> I must say the former solution is much more appealing to me.
>
> I think it's natural to expect that user can denote field as "required". This
> information is important to display as much as to actual validation. And
> TextField(..., is_required=True) does this just fine.
>
> To specify data validation/conversion current syntax can be used:
> TextField(validator=Int(not_empty=True)))
> If is_required is set, it can override validator's not_empty param and/or
> raise exception on mismatch.
>
> I can propose another syntax which somewhat cleaner but not
> backward-compatible:
>
> TextField(validator=Int, is_required=False, **extra_validator_args)
>
> Note that validator specify class object, not an instance. FormField would
> instantiate validator using is_required and extra_validator_args if any.
>
> My 2 cents.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---