diff --git a/tests/backoffice_pages/test_submission.py b/tests/backoffice_pages/test_submission.py index 8d1bf9fb2..818b17332 100644 --- a/tests/backoffice_pages/test_submission.py +++ b/tests/backoffice_pages/test_submission.py @@ -1687,7 +1687,13 @@ def test_backoffice_submission_user_selection_then_live_prefill(pub): assert resp.pyquery('.submit-user-selection') resp.form['user_id'] = str(random_user.id) # happens via javascript live_resp = app.post(live_url + '?modified_field_id=user', params=resp.form.submit_fields()) - assert live_resp.json == {'result': {'3': {'visible': True, 'content': 'test9@invalid'}}} + assert live_resp.json == {'result': {'3': {'visible': True, 'content': 'test9@invalid', 'locked': False}}} + + # check with locked field + formdef.fields[1].prefill['locked'] = True + formdef.store() + live_resp = app.post(live_url + '?modified_field_id=user', params=resp.form.submit_fields()) + assert live_resp.json == {'result': {'3': {'visible': True, 'content': 'test9@invalid', 'locked': True}}} def test_backoffice_submission_user_selection_then_card_data_source(pub): diff --git a/wcs/forms/common.py b/wcs/forms/common.py index 24ffea75e..018eb78ef 100644 --- a/wcs/forms/common.py +++ b/wcs/forms/common.py @@ -948,8 +948,9 @@ class FormStatusPage(Directory, FormTemplateMixin): elif field.get_prefill_configuration().get('type') == 'user': update_prefill = bool(get_request().form.get('modified_field_id') == 'user') if update_prefill: - value = field.get_prefill_value(user=formdata.user)[0] + value, locked = field.get_prefill_value(user=formdata.user) entry['content'] = value + entry['locked'] = locked return json.dumps({'result': result}) diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index e35fa0d46..cecfd7674 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -611,6 +611,10 @@ $(function() { $(widget).find('input[type=radio]').prop('checked', false); $(widget).find('input[type=radio][value="'+value.content+'"]').prop('checked', true); } + if (data.modified_field == 'user' && value.locked) { + $(widget).addClass('widget-readonly'); + $(widget).find('input').attr('readonly', 'readonly'); + } } } });