Jorge Godoy wrote: > > You mean something like: > > class my_fields(widgets.WidgetsList): > field1 = widgets.TextField( > label = _(u'some label'), > is_required = False, > ) > > class my_validators(validators.Schema): > field1 = validators.UnicodeString(not_empty = True) > > ? >
Yes, this will not work. > > Because you're not attributing a default value everywhere the widget is used. > If you use it in 5 different places, then there will be the same default in > all of those. I also don't like it and haven't used it, but I believe there > might be some utility in that. > > It's the same thing that setting getters and setters within the model: why not > do it all in the controller? Because it is cleaner, it is more consistent and > it is nearer the "affected" part of your system. > > Also, if_invalid can be used to do some kind of redirection, post-processing > or even changing something within the program flow (is this good? I > dunno...). > Yep, if Ian added it there is probably a good reason. ;-) > > So what is the obvious way? > > - using the validator parameter and not_empty > > +1 > > > - using is_required > > I don't see this as a solution since there are already many idioms within FE > (and our widgets) for that: not_empty, allow_empty and validators.NotEmpty(). > Besides that, we already have if_empty to deal with empty values (that might > need being combined with some of the validators to achieve what one desires). > > Adding another alternative would just make things worse... > That's in fact what I've tried to explain, is_required breaks consistency and adds confusion, we should only rely on FE. > > With the last solution you have only this way: > > > > 1) a new validator > > TextField(validator=Int(not_empty=True)) > > > > 2) tweak the default validator > > TextField(validator_args=dict(not_empty=True)) > > Hmmm... I don't like the idea of a "default validator" that's not exactly the > same that is specified in FE's docs. And I still prefer explicitly stating > what I want -- not_empty = False, if_empty = 'abc' -- than having to guess > what the default is and then combine the results. Besides, just "adding to > the default" might cause surprises if the default changes. > ?? I think you're misunderstanding what I intend for default validator, for a FileField this will be FileUploadStorage... for a multiple selection field the validator becomes more difficult and I wouldn't except anyone being happy to drop the default validator you get in this case: CheckBoxList(options=[(1, "python"), (2, "java")]) to do this instead: CheckBoxList(options=[(1, "python"), (2, "java")], validator=MultipleSelection(Int())) > > no conflicts, at init if validator is not None validators_args is not > > considered, anyway no one will use validator and validator_args (better > > name please) at the same time since it's obvious the use case they > > cover, "obvious way to do it". > > Why having both? :-) > You're right see below... > > validator -> brand new FE validador > > validator_args -> arguments for the default *FE* validator provided by > > the widget > > I don't like validator_args... > Me too: see my last reply to Max with a new solution, use validator for everything. > > What is the problem of saying: > > field = widgets.FileField(validator=UnicodeString(not_empty=True), > css_classes = ['required'], > ) > > ? It is much clearer that this filefield widget will accept thos funky > Windows files named like "saúde.doc" (health.doc), that it can't be empty and > that it should have the CSS class 'required', for layouting purposes... > Mmm, I thought you liked the auto css class for required fields. :-( Ciao Michele --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
