Skip to content

Commit

Permalink
FIO-7724 fixed metadata for multiple select (#5453)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaKurban authored Jan 16, 2024
1 parent f4b2b92 commit ade37ab
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
comp17,
comp18,
comp19,
comp20
} from './fixtures';

// eslint-disable-next-line max-statements
Expand Down Expand Up @@ -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');
Expand Down
45 changes: 45 additions & 0 deletions src/components/select/fixtures/comp20.js
Original file line number Diff line number Diff line change
@@ -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'
};
3 changes: 2 additions & 1 deletion src/components/select/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit ade37ab

Please sign in to comment.