[twill] Setting ListControls by Value

sureshvv suresh_vv at yahoo.com
Mon Nov 28 01:04:33 PST 2005

I needed to be able to set a list control by value.
So I added three lines to the set_form_control_value method in utils.py
as shown:


def set_form_control_value(control, val):
     Helper function to deal with setting form values on lists etc.
     if isinstance(control, ClientForm.ListControl):
 >        if val[0:2] == '__':
 >            control.set(1, val[2:], by_label=True )
 >        else:
             control.set(1, val)
         control.value = val


Basically you need to prefix the value with __ (two underscores).

It works for me. The syntax may be somewhat and could be improved ;)


More information about the twill mailing list