Alberto Valverde a écrit :
> On Dec 8, 2006, at 11:51 AM, remi jolin wrote:
>
>
>> Hello,
>>
>> I have a form with a MultipleSelectField(validator=validators.Int()),
>> options are something like [(1, "aaa"), (2, "bbb"), ...]
>> If I select a single element I get an integer. That's OK.
>> But, if I select multiple elements, I get a list of strings like
>> [u'1',
>> u'2'] where I was hopping to get [1, 2].
>>
>> Is it the standard behaviour ?
>>
>
> No. You should be geting a list of ints. It might be a bug... :( Can
> you send some code that reproduces this problem (a test case that
> could be included in the widgets' test suite would be awesome) so I
> can check it out?
>
> Thanks :)
>
>
Here is a small example.
----------------
import logging
import cherrypy
import turbogears
from turbogears import controllers, expose, validate, redirect
from turbogears import widgets, validators
log = logging.getLogger("mm.controllers")
class MyField(widgets.WidgetsList):
my_selection = widgets.MultipleSelectField(options=[(1, "aa"),
(2, "bb"),
(3, "cc")])#,
#validator=validators.Int())
class MultipleSelectForm(widgets.TableForm):
fields = MyField()
class Root(controllers.RootController):
@expose(template="mm.templates.test_select")
def test_select(self, my_selection=None, **kw):
print ">>> ", my_selection, " <<<"
return dict(MultipleSelectForm=MultipleSelectForm())
@expose(template="mm.templates.welcome")
def index(self):
import time
log.debug("Happy TurboGears Controller Responding For Duty")
return dict(now=time.ctime())
----------------------------
test_select.kid has a single <div>${MultipleSelectForm.display()}</div>
When I call test_select and select a single element (bbb) the print
gives >>> 2 <<<
If I select "aa" and "cc" I get >>> [u'1', u'3'] <<<
Another question is why I don't get a list (like [2]) when I select a
single element ??
I tried to setup a test like this
form = MultipleSelectForm()
v = dict(MySelection=[u'1', u'2']
r = form.validate(v)
I get [1, 2] in r has expected...
(TurboGears 1.0b1)
> Alberto
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---