z3c.form uses a widget for sorted collections (like lists) which is implemented using JavaScript. (See the example image.) But this widget is testable using zope.testbrowser, too.
Example in-out-widget of a list
As the widget in the image is named "columns" (title and name of the schema element are the same in the examle), the left select control is named form.widgets.columns.from. The right select control is named form.widgets.columns.to. On submit the values of the items in the right control get stored in a hidden fields named form.widgets.columns:list. To select the "person -- birthdate" control additionally to the ones in the right select control, you can use the following code:
>>> def in_out_select(form, name, control_name):
... form.mech_form.new_control(
... type='hidden',
... name=name,
... attrs=dict(value=browser.getControl(control_name).optionValue))
>>> form = browser.getForm()
>>> in_out_select(form, 'form.widgets.columns:list', 'person -- birth date'))
>>> in_out_select(form, 'form.widgets.columns:list', 'person -- first name'))
>>> in_out_select(form, 'form.widgets.columns:list', 'person -- last name'))
Comment (1)
Perhaps the implementation changed, but I had to supply additional parameters for browser.getForm() - at least an index, thus selection the first form on the page with 0:
form = browser.getForm(index=0)
otherwise: ValueError: if no other arguments are given, index is required.
Add a Comment