Skip to content

Commit

Permalink
FIO-9283: fixed na issue where select with resource dataSrc does not …
Browse files Browse the repository at this point in the history
…display values in readOnly mode (#5893)

* FIO-9283: fixed na issue where select with resource dataSrc does not display values in readOnly mode

* fixed tests
  • Loading branch information
TanyaGashtold authored Nov 4, 2024
1 parent d8f94f4 commit 2079440
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Form.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

Expand Down
39 changes: 38 additions & 1 deletion test/unit/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import {
comp24,
comp25,
comp26,
comp27
comp27,
comp28
} from './fixtures/select';

// eslint-disable-next-line max-statements
Expand Down Expand Up @@ -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));
});
});
59 changes: 59 additions & 0 deletions test/unit/fixtures/select/comp28.js
Original file line number Diff line number Diff line change
@@ -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: '<span>{{ item.data.textField }}</span>',
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',
};
3 changes: 2 additions & 1 deletion test/unit/fixtures/select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit 2079440

Please sign in to comment.