Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8072: Added conditional operators for select component with number data type #5656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export default class SelectComponent extends ListComponent {
}

static get conditionOperatorsSettings() {
const numberType = () => ({ type: 'number' });

return {
...super.conditionOperatorsSettings,
valueComponent(classComp) {
Expand All @@ -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,
},
},
};
}

Expand Down
36 changes: 36 additions & 0 deletions src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
comp22,
comp23,
comp24,
comp25,
} from './fixtures';

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