Project

General

Profile

0001-forms-don-t-modify-normal-keys-in-checkboxes-widget-.patch

Thomas Noël, 04 Nov 2016 04:15 PM

Download (2.64 KB)

View differences:

Subject: [PATCH] forms: don't modify "normal" keys in checkboxes widget
 (#13870)

 tests/test_form_pages.py | 24 ++++++++++++++++++++++++
 wcs/qommon/form.py       |  4 ++--
 2 files changed, 26 insertions(+), 2 deletions(-)
tests/test_form_pages.py
385 385
    data = formdef.data_class().get(data_id)
386 386
    assert data.data == {'0': 'foobar'}
387 387

  
388
def test_form_items_submit(pub):
389
    formdef = create_formdef()
390
    formdef.fields = [fields.ItemsField(id='0', label='items', type='items',
391
                required=True,
392
                varname='foo', items=['Foo', 'Bar', 'Three']),]
393
    formdef.store()
394
    formdef.data_class().wipe()
395
    page = get_app(pub).get('/test/')
396
    next_page = page.forms[0].submit('submit') # but the field is required
397
    assert '<div class="error">required field</div>' in next_page.body
398
    next_page.forms[0]['f0$element0'].checked = True
399
    next_page.forms[0]['f0$element1'].checked = True
400
    next_page = next_page.forms[0].submit('submit')
401
    assert 'Check values then click submit.' in next_page.body
402
    next_page = next_page.forms[0].submit('submit')
403
    assert next_page.status_int == 302
404
    next_page = next_page.follow()
405
    assert 'The form has been recorded' in next_page.body
406
    assert formdef.data_class().count() == 1
407
    data_id = formdef.data_class().select()[0].id
408
    data = formdef.data_class().get(data_id)
409
    assert data.data['0'] == ['Foo', 'Bar']
410
    assert data.data['0_display'] == 'Foo, Bar'
411

  
388 412
def assert_current_page(resp, page_label):
389 413
    assert re.findall('<li class=".*?current.*?">.*?<span class="label">(.*?)</span></li>',
390 414
            resp.body)[0] == page_label
wcs/qommon/form.py
1139 1139
        for i, option in enumerate(options):
1140 1140
            if len(option) == 2:
1141 1141
                key, title = option[:2]
1142
                key = str(i)
1142
                name = 'element%d' % i
1143 1143
            else:
1144 1144
                _, title, key  = option[:3]
1145
                name = 'element%s' % str(key)
1145 1146

  
1146 1147
            key = str(key)
1147
            name = 'element%s' % key
1148 1148

  
1149 1149
            element_kwargs = kwargs.copy()
1150 1150
            if self.options_with_attributes and option[-1].get('disabled'):
1151
-