diff --git a/src/components/select/Select.js b/src/components/select/Select.js index fdbb2c1fa6..f9957eb7ed 100644 --- a/src/components/select/Select.js +++ b/src/components/select/Select.js @@ -63,6 +63,8 @@ export default class SelectComponent extends ListComponent { } static get conditionOperatorsSettings() { + const numberType = () => ({ type: 'number' }); + return { ...super.conditionOperatorsSettings, valueComponent(classComp) { @@ -81,7 +83,18 @@ export default class SelectComponent extends ListComponent { } return valueComp; - } + }, + dataTypeOperators: { + number: ['lessThan', 'greaterThan', 'lessThanOrEqual', 'greaterThanOrEqual'], + }, + dataTypeValueComponents: { + number: { + lessThan: numberType, + greaterThan: numberType, + lessThanOrEqual: numberType, + greaterThanOrEqual: numberType, + }, + }, }; } diff --git a/src/components/select/Select.unit.js b/src/components/select/Select.unit.js index 372002c9cb..285c24d88d 100644 --- a/src/components/select/Select.unit.js +++ b/src/components/select/Select.unit.js @@ -34,6 +34,7 @@ import { comp22, comp23, comp24, + comp25, } from './fixtures'; // eslint-disable-next-line max-statements @@ -1154,6 +1155,41 @@ describe('Select Component', () => { }).catch(done); }); + it('Should perfom simple conditional logic for number data type', (done) => { + const form = _.cloneDeep(comp25); + const element = document.createElement('div'); + + Formio.createForm(element, form).then(form => { + const select = form.getComponent('select'); + const textfield = form.getComponent('textField'); + select.setValue('1'); + + setTimeout(() => { + assert.equal(select.dataValue, 1); + assert.equal(textfield.visible, true); + select.setValue('2'); + + setTimeout(() => { + assert.equal(select.dataValue, 2); + assert.equal(textfield.visible, true); + select.setValue('10'); + + setTimeout(() => { + assert.equal(select.dataValue, 10); + assert.equal(textfield.visible, false); + select.setValue('1d'); + + setTimeout(() => { + assert.equal(select.dataValue, '1d'); + assert.equal(textfield.visible, false); + done(); + }, 300); + }, 300); + }, 300); + }, 300); + }).catch(done); + }); + // it('should reset input value when called with empty value', () => { // const comp = Object.assign({}, comp1); // delete comp.placeholder; diff --git a/src/components/select/fixtures/comp25.js b/src/components/select/fixtures/comp25.js new file mode 100644 index 0000000000..224577f347 --- /dev/null +++ b/src/components/select/fixtures/comp25.js @@ -0,0 +1,57 @@ +export default { + title: 'FIO-8072', + name: 'fio8072', + path: 'fio8072', + type: 'form', + display: 'form', + components: [ + { + label: 'Select', + widget: 'choicesjs', + tableView: true, + data: { + values: [ + { + label: 'A', + value: '1', + }, + { + label: 'B', + value: '2', + }, + { + label: 'C', + value: '10', + }, + { + label: 'D', + value: '1d', + }, + ], + }, + dataType: 'number', + key: 'select', + type: 'select', + input: true, + }, + { + label: 'Text Field', + applyMaskOn: 'change', + tableView: true, + key: 'textField', + type: 'textfield', + input: true, + conditional: { + show: true, + conjunction: 'all', + conditions: [ + { + component: 'select', + operator: 'lessThan', + value: 5, + }, + ], + }, + }, + ], +}; diff --git a/src/components/select/fixtures/index.js b/src/components/select/fixtures/index.js index d45d0d3b0a..022cc78ef0 100644 --- a/src/components/select/fixtures/index.js +++ b/src/components/select/fixtures/index.js @@ -22,4 +22,5 @@ import comp21 from './comp21'; import comp22 from './comp22'; import comp23 from './comp23'; import comp24 from './comp24'; -export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19, comp20, comp21, comp22, comp23, 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 };