diff --git a/js/ui/filter_builder/between.js b/js/ui/filter_builder/between.js index 320f91517cc7..3d702b1f5cee 100644 --- a/js/ui/filter_builder/between.js +++ b/js/ui/filter_builder/between.js @@ -50,7 +50,8 @@ function getConfig(caption, context) { icon: 'range', valueSeparator: SEPARATOR, dataTypes: ['number', 'date', 'datetime'], - editorTemplate: editorTemplate.bind(context) + editorTemplate: editorTemplate.bind(context), + notForLookup: true }; } diff --git a/js/ui/filter_builder/utils.js b/js/ui/filter_builder/utils.js index db912363749d..5a72980ca62a 100644 --- a/js/ui/filter_builder/utils.js +++ b/js/ui/filter_builder/utils.js @@ -194,11 +194,12 @@ function getCustomOperation(customOperations, name) { function getAvailableOperations(field, filterOperationDescriptions, customOperations) { const filterOperations = getFilterOperations(field); - + const isLookupField = !!field.lookup; customOperations.forEach(function(customOperation) { if(!field.filterOperations && filterOperations.indexOf(customOperation.name) === -1) { const dataTypes = customOperation && customOperation.dataTypes; - if(dataTypes && dataTypes.indexOf(field.dataType || DEFAULT_DATA_TYPE) >= 0) { + const isOperationForbidden = isLookupField ? !!customOperation.notForLookup : false; + if(!isOperationForbidden && dataTypes && dataTypes.indexOf(field.dataType || DEFAULT_DATA_TYPE) >= 0) { filterOperations.push(customOperation.name); } } diff --git a/testing/tests/DevExpress.ui.widgets/filterBuilderParts/utilsTests.js b/testing/tests/DevExpress.ui.widgets/filterBuilderParts/utilsTests.js index 76a46371e743..5565cf8f7f41 100644 --- a/testing/tests/DevExpress.ui.widgets/filterBuilderParts/utilsTests.js +++ b/testing/tests/DevExpress.ui.widgets/filterBuilderParts/utilsTests.js @@ -23,18 +23,19 @@ const groupOperations = [{ value: '!or' }]; const filterOperationsDescriptions = { + between: 'Is between', + contains: 'Contains', + endsWith: 'Ends with', equal: 'Equals', - notEqual: 'Does not equal', - lessThan: 'Is less than', - lessThanOrEqual: 'Is less than or equal to', greaterThan: 'Is greater than', greaterThanOrEqual: 'Is greater than or equal to', - startsWith: 'Starts with', - contains: 'Contains', - notContains: 'Does not contain', - endsWith: 'Ends with', isBlank: 'Is blank', - isNotBlank: 'Is not blank' + isNotBlank: 'Is not blank', + lessThan: 'Is less than', + lessThanOrEqual: 'Is less than or equal to', + notContains: 'Does not contain', + notEqual: 'Does not equal', + startsWith: 'Starts with' }; QUnit.module('Errors', function() { @@ -1121,6 +1122,54 @@ QUnit.module('getAvailableOperations', { // assert assert.strictEqual(operations[0].text, 'Last Days'); }); + + // T889066 + QUnit.test('a custom operation with enabled notForLookup option should not be listed for a lookup column', function(assert) { + // arrange, act + const customOperations = [ + { + name: 'test1', + notForLookup: true, + dataTypes: ['number'] + }, + { + name: 'test2', + notForLookup: false, + dataTypes: ['number'] + }, + { + name: 'test3', + dataTypes: ['number'] + } + ]; + const field1 = { + dataField: 'test', + dataType: 'number' + }; + const field2 = { + dataField: 'test', + dataType: 'number', + lookup: {} + }; + + // act + let operations = utils.getAvailableOperations(field1, filterOperationsDescriptions, customOperations); + let operationValues = operations.map(operation => operation.value); + + // assert + assert.ok(operationValues.indexOf('test1') >= 0, 'test1 is in the list'); + assert.ok(operationValues.indexOf('test2') >= 0, 'test2 is in the list'); + assert.ok(operationValues.indexOf('test3') >= 0, 'test3 is in the list'); + + // act + operations = utils.getAvailableOperations(field2, filterOperationsDescriptions, customOperations); + operationValues = operations.map(operation => operation.value); + + // assert + assert.equal(operationValues.indexOf('test1'), -1, 'test1 is not listed'); + assert.ok(operationValues.indexOf('test2') >= 0, 'test2 is in the list'); + assert.ok(operationValues.indexOf('test3') >= 0, 'test3 is in the list'); + }); }); QUnit.module('Custom filter expressions', {