From ae65b7efc330eaf84844cd4d16e02c8f6db610ac Mon Sep 17 00:00:00 2001 From: Hanna Kurban Date: Thu, 11 Jan 2024 18:29:02 +0300 Subject: [PATCH] FIO-7724 fixed metadata for multiple select --- src/components/select/Select.js | 1 + src/components/select/Select.unit.js | 28 +++++++++++++++ src/components/select/fixtures/comp20.js | 45 ++++++++++++++++++++++++ src/components/select/fixtures/index.js | 3 +- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/components/select/fixtures/comp20.js diff --git a/src/components/select/Select.js b/src/components/select/Select.js index a809818111..67dcc9fa6f 100644 --- a/src/components/select/Select.js +++ b/src/components/select/Select.js @@ -1397,6 +1397,7 @@ export default class SelectComponent extends ListComponent { templateData[dataValueItemValue] = this.templateData[dataValueItemValue]; }); } + templateData[value] = this.templateData[value]; } _.set(submission.metadata.selectData, this.path, templateData); diff --git a/src/components/select/Select.unit.js b/src/components/select/Select.unit.js index b3eef6b391..bc96c83e78 100644 --- a/src/components/select/Select.unit.js +++ b/src/components/select/Select.unit.js @@ -29,6 +29,7 @@ import { comp17, comp18, comp19, + comp20 } from './fixtures'; // eslint-disable-next-line max-statements @@ -921,6 +922,33 @@ describe('Select Component', () => { }).catch(done); }); + it('Should provide correct metadata.selectData for multiple Select', (done) => { + const form = _.cloneDeep(comp20); + const element = document.createElement('div'); + + Formio.createForm(element, form).then(form => { + const select = form.getComponent('select'); + const values = ['apple', 'orange']; + select.setValue(values); + + setTimeout(()=> { + const submit = form.getComponent('submit'); + const clickEvent = new Event('click'); + const submitBtn = submit.refs.button; + submitBtn.dispatchEvent(clickEvent); + + setTimeout(() => { + const metadata = form.submission.metadata.selectData.select; + assert.equal(_.keys(metadata).length, 2); + values.forEach((value) => { + assert.equal(_.find(select.component.data.values, { value }).label, metadata[value].label); + }); + done(); + }, 200); + }, 200); + }).catch(done); + }); + it('OnBlur validation should work properly with Select component', function(done) { this.timeout(0); const element = document.createElement('div'); diff --git a/src/components/select/fixtures/comp20.js b/src/components/select/fixtures/comp20.js new file mode 100644 index 0000000000..69ff024e7a --- /dev/null +++ b/src/components/select/fixtures/comp20.js @@ -0,0 +1,45 @@ +export default { + _id: '659fa81f4a40147c0ffb949b', + title: '7724', + name: '7724', + path: '7724', + type: 'form', + display: 'form', + components: [ + { + label: 'Select', + widget: 'choicesjs', + tableView: true, + multiple: true, + data: + { + values: [ + { + label: 'Apple', + value: 'apple' + }, + { + label: 'Orange', + value: 'orange' + }, + { + label: 'Pear', + value: 'pear' + } + ] + }, + key: 'select', + type: 'select', + input: true + }, + { + type: 'button', + label: 'Submit', + key: 'submit', + disableOnInvalid: true, + input: true, + tableView: false + } + ], + project: '63cead09be0090345b109e22' +}; diff --git a/src/components/select/fixtures/index.js b/src/components/select/fixtures/index.js index b1ed9a6150..0fa3a99cc4 100644 --- a/src/components/select/fixtures/index.js +++ b/src/components/select/fixtures/index.js @@ -17,4 +17,5 @@ import comp16 from './comp16'; import comp17 from './comp17'; import comp18 from './comp18'; import comp19 from './comp19'; -export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19 }; +import comp20 from './comp20'; +export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19, comp20 };