On 7/9/06, Kevin Dangoor <[EMAIL PROTECTED]> wrote:
> On Jul 7, 2006, at 9:45 AM, Ed Singleton wrote:
>
> >
> > I've having problems putting an optional FileField on my form.
> >
> > If I use:
> > FileField("photo", validator=validators.FieldStorageUploadConverter())
> >
> > and don't enter a photo, then it returns a tg_error of "invalid" for
> > the field (which isn't a helpful error message).
> >
> > If I use:
> > FileField("photo",
> > validator=validators.Any(validators.FieldStorageUploadConverter
> > (),validators.Empty()))
> >
> > then I get the error message below.
> >
> > Any ideas on how to make the field optional, yet vaildate correctly if
> > there is something in it?
>
>
> I'd call that a bug (or at least lack of a good feature...)
>
> There should be an explicit way to set that field to optional, and I
> don't see one with the quick glance I just gave to the code.
Shouldn't there be an explicit way to set any field to optional?
Currently it seems to decide based on whether there is a validator:
widgets/forms.py
...
332 class FormField(InputWidget):
...
350 def _get_is_required(self):
351 validator = self._retrieve_validator_from_validation_schema()
352 if validator is None:
353 return False
354 else:
355 try:
356 validator.to_python('')
357 except validators.Invalid:
358 return True
359 else:
360 return False
361 is_required = property(_get_is_required)
Could I just add something in there which checks for a "optional=True"
parameter?
Ed
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---