Validator error for form with SingleSelectField

10 views
Skip to first unread message

Christopher Arndt

unread,
Jan 30, 2007, 7:17:24 AM1/30/07
to turbo...@googlegroups.com
Please see the code at

http://paste.turbogears.org/paste/935

This gives me the following error on app startup:

[...]
File "<myproject>/widgets/base.py", line 13, in ?
class TestFormFields(widgets.WidgetsList):
File "<myproject>/widgets/base.py", line 18, in TestFormFields
options=[]
File
"<myenv>/lib/python2.4/TurboGears-1.0.1-py2.4.egg/turbogears/widgets/meta.py",
line 142, in widget_init
func(self, *args, **kw)
File
"<myenv>/lib/python2.4/TurboGears-1.0.1-py2.4.egg/turbogears/widgets/forms.py",
line 841, in __init__
raise ValueError, ("No validator specified and couldn't "
ValueError: No validator specified and couldn't guess one. I cannot work
properly without it

As you can see, I'm using TurboGears 1.0.1 in a pristine workingenv. I'm
also using kid 0.9.5.

Can anybody tell me what's happening here? The error always happens when
I try to add a SingleSelectField to my form, regardless of which other
fields I define in my form. It doesN't seem to matter, whether I
actually specify a validation schema in the form instantiation or not.

Chris

Ed Singleton

unread,
Jan 30, 2007, 7:57:20 AM1/30/07
to turbo...@googlegroups.com
You need to have some options in your options so that it can guess
what validator to use.

You can put in some dummy options and override them later, or put in
the options you will be using.

For example changing this line works:

options=[(1,'One'), (2,'Two')]

Ed

Jorge Godoy

unread,
Jan 30, 2007, 8:22:21 AM1/30/07
to turbo...@googlegroups.com
"Ed Singleton" <singl...@gmail.com> writes:

> You need to have some options in your options so that it can guess
> what validator to use.
>
> You can put in some dummy options and override them later, or put in
> the options you will be using.
>
> For example changing this line works:
>
> options=[(1,'One'), (2,'Two')]

Even though this solves the problem this should be considered a bug, IMHO.

The guessing should only occur when there's no validator specified. Here he
said explicitly to use a validators.Int() validator, so there's no need to
guess anything.


Also, IMHO, a better workaround would be specifying a default validator at the
widget instantiation and then overriding it at the validator schema.


--
Jorge Godoy <jgo...@gmail.com>

Christopher Arndt

unread,
Jan 30, 2007, 10:19:55 AM1/30/07
to turbo...@googlegroups.com
Jorge Godoy schrieb:

> "Ed Singleton" <singl...@gmail.com> writes:
>
>> You need to have some options in your options so that it can guess
>> what validator to use.

Wow, that's a crappy API!

> Also, IMHO, a better workaround would be specifying a default validator at the
> widget instantiation and then overriding it at the validator schema.

Will try that!

Chris

Jorge Godoy

unread,
Jan 30, 2007, 10:59:10 AM1/30/07
to turbo...@googlegroups.com
Christopher Arndt <chris...@web.de> writes:

> Jorge Godoy schrieb:
>> "Ed Singleton" <singl...@gmail.com> writes:
>>
>>> You need to have some options in your options so that it can guess
>>> what validator to use.
>
> Wow, that's a crappy API!

This isn't needed. I have some SingleSelectFields where I don't have any
options... But I always have a default validator.

>> Also, IMHO, a better workaround would be specifying a default validator at the
>> widget instantiation and then overriding it at the validator schema.
>
> Will try that!

Don't forget filing a bug... It should work with the schema without the
default validator...

--
Jorge Godoy <jgo...@gmail.com>

Alberto Valverde

unread,
Jan 30, 2007, 5:45:38 PM1/30/07
to turbo...@googlegroups.com

On Jan 30, 2007, at 4:19 PM, Christopher Arndt wrote:

>
> Jorge Godoy schrieb:
>> "Ed Singleton" <singl...@gmail.com> writes:
>>
>>> You need to have some options in your options so that it can guess
>>> what validator to use.
>
> Wow, that's a crappy API!

I'll have to agree with you ;)

http://tinyurl.com/3xwsa7
http://tinyurl.com/2tzvu2

The best way to fix it is to define a validator explicitly in the
field, not in the schema.

That guessing behavior is there in order to keep backwards
compatibility, fortunately I've removed it from twForms in which you
need to explicitly define a validator for each field that needs one.
An exception being repeated fields in which a ForEach validator is
built (if none given) using the individual field's one, same for
multiple select fields; and forms, which create (or extend an
existing one) with the children's validators.

Alberto

Reply all
Reply to author
Forward
0 new messages