diff --git a/src/components/select/Select.js b/src/components/select/Select.js index bc322f1a01..068b2dd29e 100644 --- a/src/components/select/Select.js +++ b/src/components/select/Select.js @@ -1490,7 +1490,7 @@ export default class SelectComponent extends ListComponent { _.set(submission.metadata.selectData, this.path, templateData); } - if (flags.resetValue && this.root?.submission) { + if (flags.resetValue && this.root?.submission && !this.options.readOnly) { const submission = this.root.submission; if (!submission.metadata) { submission.metadata = {}; diff --git a/test/unit/Form.unit.js b/test/unit/Form.unit.js index 93dd956f04..19867a3bbb 100644 --- a/test/unit/Form.unit.js +++ b/test/unit/Form.unit.js @@ -512,8 +512,8 @@ describe('SaveDraft functionality for Nested Form', () => { assert.equal(state, 'draft'); _.unset(comp7.components[1], 'reference'); done(); - }, 1000); - }, 200); + }, 1100); + }, 300); }).catch((err) => done(err)); }); diff --git a/test/unit/Select.unit.js b/test/unit/Select.unit.js index e6b0b12a92..40b7d4eb18 100644 --- a/test/unit/Select.unit.js +++ b/test/unit/Select.unit.js @@ -37,7 +37,8 @@ import { comp24, comp25, comp26, - comp27 + comp27, + comp28 } from './fixtures/select'; // eslint-disable-next-line max-statements @@ -1554,4 +1555,40 @@ describe('Select Component with Entire Object Value Property', () => { }) .catch((err) => done(err)); }); + + it('Should render label for Select Resource type in readOnly mode', (done) => { + const element = document.createElement('div'); + Formio.createForm(element, comp28, { readOnly: true }).then((form) => { + const select = form.getComponent('selectResource'); + form.setSubmission({ + form: '672483c1d9abe46bcd70bca4', + metadata: { + selectData: { + selectResource: { + data: { + textField: 'test1', + }, + }, + }, + }, + data: { + selectResource: 'test1', + submit: true, + }, + _id: '6724d15cd9abe46bcd7115d1', + project: '67211a9aa929e4e6ebc2bf77', + state: 'submitted', + created: '2024-11-01T13:02:20.349Z', + modified: '2024-11-01T13:02:20.349Z', + }); + + setTimeout(() => { + const previewSelect = select.element.querySelector('[aria-selected="true"] span'); + assert.equal(previewSelect.innerHTML, 'test1'); + + done(); + }, 400); + }) + .catch((err) => done(err)); + }); }); diff --git a/test/unit/fixtures/select/comp28.js b/test/unit/fixtures/select/comp28.js new file mode 100644 index 0000000000..e8956a0ab2 --- /dev/null +++ b/test/unit/fixtures/select/comp28.js @@ -0,0 +1,59 @@ +export default { + _id: '672483c1d9abe46bcd70bca4', + title: 'yyyyyyy', + name: 'yyyyyyy', + path: 'yyyyyyy', + type: 'form', + display: 'form', + components: [ + { + label: 'Number', + applyMaskOn: 'change', + mask: false, + tableView: false, + delimiter: false, + requireDecimal: false, + inputFormat: 'plain', + truncateMultipleSpaces: false, + validateWhenHidden: false, + key: 'number', + type: 'number', + input: true, + }, + { + label: 'Select - Resource', + widget: 'choicesjs', + tableView: true, + dataSrc: 'resource', + data: { + resource: '672482f2d9abe46bcd70a0dc', + }, + valueProperty: 'data.textField', + template: '{{ item.data.textField }}', + validate: { + select: false, + }, + validateWhenHidden: false, + key: 'selectResource', + type: 'select', + searchField: 'data.textField__regex', + noRefreshOnScroll: false, + addResource: false, + reference: false, + input: true, + searchThreshold: 0.3, + }, + { + type: 'button', + label: 'Submit', + key: 'submit', + disableOnInvalid: true, + input: true, + tableView: false, + }, + ], + project: '67211a9aa929e4e6ebc2bf77', + created: '2024-11-01T07:31:13.647Z', + modified: '2024-11-01T12:51:23.213Z', + machineName: 'izutenexavvxnws:yyyyyyy', +}; diff --git a/test/unit/fixtures/select/index.js b/test/unit/fixtures/select/index.js index c1811cfe2c..174bea6b33 100644 --- a/test/unit/fixtures/select/index.js +++ b/test/unit/fixtures/select/index.js @@ -25,4 +25,5 @@ import comp24 from './comp24'; import comp25 from './comp25'; import comp26 from './comp26'; import comp27 from './comp27'; -export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19, comp20, comp21, comp22, comp23, comp24, comp25, comp26, comp27 }; +import comp28 from './comp28'; +export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19, comp20, comp21, comp22, comp23, comp24, comp25, comp26, comp27, comp28};