diff --git a/src/components/select/Select.js b/src/components/select/Select.js index f9957eb7ed..22c3473595 100644 --- a/src/components/select/Select.js +++ b/src/components/select/Select.js @@ -1774,7 +1774,7 @@ export default class SelectComponent extends ListComponent { if (Array.isArray(data)) { data.forEach((item) => item[valueProperty] = item[valueProperty].toString()); } - else { + else if (_.isObject(data)) { data[valueProperty] = data[valueProperty].toString(); } return data; @@ -1818,7 +1818,7 @@ export default class SelectComponent extends ListComponent { }; value = (this.component.multiple && Array.isArray(value)) ? _.filter(items, (item) => value.includes(item.value)) - : valueProperty + : (valueProperty && items) ? getFromValues() ?? { value, label: value } : value; } diff --git a/src/components/select/Select.unit.js b/src/components/select/Select.unit.js index 285c24d88d..ae70dc76a2 100644 --- a/src/components/select/Select.unit.js +++ b/src/components/select/Select.unit.js @@ -35,6 +35,8 @@ import { comp23, comp24, comp25, + comp26, + comp27 } from './fixtures'; // eslint-disable-next-line max-statements @@ -66,6 +68,14 @@ describe('Select Component', () => { }); }); + it('should return string value if dataSrc set as custom', function(done) { + Harness.testCreate(SelectComponent, comp27).then((component) => { + const stringValue = component.asString('California'); + assert.equal(stringValue, 'California'); + done(); + }); + }) + it('Should return plain text when csv option is provided', () => { return Harness.testCreate(SelectComponent, comp1).then((component) => { assert.equal(component.getView('red', { csv:true }), 'Red'); diff --git a/src/components/select/fixtures/comp27.js b/src/components/select/fixtures/comp27.js new file mode 100644 index 0000000000..0aba996c21 --- /dev/null +++ b/src/components/select/fixtures/comp27.js @@ -0,0 +1,17 @@ +export default { + type: 'select', + label: 'Select', + widget: 'choicesjs', + tableView: true, + dataSrc: 'custom', + data: { + custom: 'values = data.dataSource;' + }, + dataType: 'string', + idPath: 'name', + valueProperty: 'name', + template: '{{ item.name }}', + validateWhenHidden: false, + key: 'select', + input: true +}; diff --git a/src/components/select/fixtures/index.js b/src/components/select/fixtures/index.js index 022cc78ef0..c1811cfe2c 100644 --- a/src/components/select/fixtures/index.js +++ b/src/components/select/fixtures/index.js @@ -23,4 +23,6 @@ import comp22 from './comp22'; import comp23 from './comp23'; import comp24 from './comp24'; import comp25 from './comp25'; -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 }; +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 };