Pylons/webtest

`MultipleSelect().value = []` doesn't work

Closed this issue · 2 comments

Steps to reproduce the behavior:

  1. Open a form with a multiple select field, with an item having value '1' (for example) already selected.

  2. Using WebTest to manipulate the form, do something like this:

     print(my_form['my_multiple_select'].value
     my_form['my_multiple_select'].value = []
     print(my_form['my_multiple_select'].value)
    

Expected result:

['1']
[]

That is, setting the select value to [] should clear all selected options, in the same way that setting to e.g. ['1'] or ['2'] will set to just a single value.

Actual result - it appears to ignore the call to set the value:

['1']
['1']

The reason for this is clear - the value__get method special cases the case of selectedIndices being empty and ignores it - https://github.com/Pylons/webtest/blob/master/webtest/forms.py#L224

gawel commented

I guess you noticed that you can use .force_value()

And yes, seems like a bug. PR welcome.

Thanks 👍