0001-forms-apply-locked-fields-after-a-block-row-is-added.patch
tests/form_pages/test_block.py | ||
---|---|---|
1367 | 1367 |
resp.form['f1$element2$f123'] = '1' |
1368 | 1368 |
resp = resp.form.submit('submit') # -> 2nd page |
1369 | 1369 |
assert resp.form['f3'].value == '9' |
1370 | ||
1371 | ||
1372 |
def test_block_add_and_locked_field(pub, blocks_feature): |
|
1373 |
FormDef.wipe() |
|
1374 |
BlockDef.wipe() |
|
1375 | ||
1376 |
block = BlockDef() |
|
1377 |
block.name = 'foobar' |
|
1378 |
block.fields = [ |
|
1379 |
fields.StringField(id='123', required=True, label='Amount', type='string', varname='amount'), |
|
1380 |
] |
|
1381 |
block.store() |
|
1382 | ||
1383 |
formdef = FormDef() |
|
1384 |
formdef.name = 'form title' |
|
1385 |
formdef.fields = [ |
|
1386 |
fields.BlockField(id='1', label='test', type='block:foobar', varname='data', max_items=3), |
|
1387 |
fields.StringField(id='2', label='foo', prefill={'type': 'string', 'value': 'Foo', 'locked': True}), |
|
1388 |
] |
|
1389 |
formdef.store() |
|
1390 | ||
1391 |
app = get_app(pub) |
|
1392 |
resp = app.get(formdef.get_url()) |
|
1393 |
assert resp.form['f2'].value == 'Foo' |
|
1394 |
assert 'readonly' in resp.form['f2'].attrs |
|
1395 |
resp.form['f1$element0$f123'] = 'a' |
|
1396 |
resp = resp.form.submit('f1$add_element') |
|
1397 |
assert resp.form['f2'].value == 'Foo' |
|
1398 |
assert 'readonly' in resp.form['f2'].attrs |
|
1399 |
resp.form['f1$element1$f123'] = 'b' |
|
1400 |
resp = resp.form.submit('f1$add_element') |
|
1401 |
resp.form['f1$element2$f123'] = 'c' |
|
1402 |
resp = resp.form.submit('submit') # -> validation page |
|
1403 |
resp = resp.form.submit('submit') # -> submit |
wcs/forms/root.py | ||
---|---|---|
360 | 360 |
prefilled = False |
361 | 361 |
locked = False |
362 | 362 | |
363 |
if add_button_clicked: |
|
364 |
if not block: |
|
365 |
# do not replay filling fields that are not part of a block |
|
366 |
continue |
|
367 |
if widget and widget.value: |
|
368 |
# do not alter subwidget values that may not yet have been |
|
369 |
# "commited" to data when an "add row" button is clicked |
|
370 |
continue |
|
371 | ||
372 | 363 |
if field.prefill: |
373 | 364 |
prefill_user = get_request().user |
374 | 365 |
if get_request().is_in_backoffice(): |
... | ... | |
379 | 370 |
# "live prefill", regardless of existing data. |
380 | 371 |
widget.prefill_attributes = field.get_prefill_attributes() |
381 | 372 | |
373 |
if widget and locked: |
|
374 |
widget.readonly = 'readonly' |
|
375 |
widget.attrs['readonly'] = 'readonly' |
|
376 | ||
377 |
if add_button_clicked: |
|
378 |
if not block: |
|
379 |
# do not replay filling fields that are not part of a block |
|
380 |
continue |
|
381 |
if widget and widget.value: |
|
382 |
# do not alter subwidget values that may not yet have been |
|
383 |
# "commited" to data when an "add row" button is clicked |
|
384 |
continue |
|
385 | ||
382 | 386 |
should_prefill = bool(field.prefill) |
383 | 387 | |
384 | 388 |
has_current_value = False |
... | ... | |
450 | 454 |
# page). |
451 | 455 |
widget.set_error(get_selection_error_text()) |
452 | 456 | |
453 |
if locked: |
|
454 |
widget.readonly = 'readonly' |
|
455 |
widget.attrs['readonly'] = 'readonly' |
|
456 | ||
457 | 457 |
had_prefill = True |
458 | 458 |
return had_prefill |
459 | 459 | |
460 |
- |