I have a problem with a singleSelect field that gets reset to its first
value when there a validation error on another field in a form.
here is a small form and a controller
def get_select_values():
return [('', '--'),
(1, 'A'),
(2, 'B'),
(3, 'C')]
new_form = widgets.TableForm(fields=[widgets.SingleSelectField('select',
options=get_select_values()),
widgets.TextField('val',
validator=validators.Int(not_empty=True))
]
)
class Root(controllers.RootController):
@expose(template='.templates.new')
def new_a(self, tg_error=None):
log.info('new_a')
if tg_error:
turbogears.flash('There was a problem with the data submitted.')
return dict(form=new_form, action='./create_a',
submit_text=u'Create...')
@expose(template='.templates.create')
@validate(form=new_form)
@error_handler(new_a)
def create_a(self, **kw):
log.info('create_a')
for p in kw:
print 'create_a ', p, ' : ', kw[p]
return dict(**kw)
---------------------
if I call the /new_a yrl, I get the form.
I select an item from the list and then click on the Create button.
(nothing in the val field, so the field is not valide) -> As expected, I
get the form back asking for a value in the 'val' field, but the value
of the select field has been reset to '--'. WHY ??
Now, if I change the options of the 'select' field like this : [(0,
'--'), (1, 'A'), (2, 'B'), (3, 'C')] (an integer for the first value
instead of ''), it works......
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---