From 34ad49a55fe877984ed8d2437046fe23718c7df2 Mon Sep 17 00:00:00 2001 From: Roman Letsuk Date: Fri, 21 Jun 2024 14:20:29 +0300 Subject: [PATCH 1/2] FIO-8072: added conditional operators for select component with number data type --- src/components/select/Select.js | 15 ++++++- src/components/select/Select.unit.js | 38 +++++++++++++++- src/components/select/fixtures/comp25.js | 57 ++++++++++++++++++++++++ src/components/select/fixtures/index.js | 3 +- 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 src/components/select/fixtures/comp25.js diff --git a/src/components/select/Select.js b/src/components/select/Select.js index 2ee58d860e..9df6e41ed9 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..e6430269f6 100644 --- a/src/components/select/Select.unit.js +++ b/src/components/select/Select.unit.js @@ -6,7 +6,7 @@ import Harness from '../../../test/harness'; import SelectComponent from './Select'; import { expect } from 'chai'; import { Formio } from './../../Formio'; -import _ from 'lodash'; +import _, { set } from 'lodash'; import { comp1, @@ -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 }; From 925a8ee85d9dbc00bbfc137e3a21771c6208943c Mon Sep 17 00:00:00 2001 From: Roman Letsuk Date: Fri, 21 Jun 2024 14:30:03 +0300 Subject: [PATCH 2/2] FIO-8072: small fix --- src/components/select/Select.unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/select/Select.unit.js b/src/components/select/Select.unit.js index e6430269f6..285c24d88d 100644 --- a/src/components/select/Select.unit.js +++ b/src/components/select/Select.unit.js @@ -6,7 +6,7 @@ import Harness from '../../../test/harness'; import SelectComponent from './Select'; import { expect } from 'chai'; import { Formio } from './../../Formio'; -import _, { set } from 'lodash'; +import _ from 'lodash'; import { comp1,