Skip to content

Commit c97301c

Browse files
authored
Disable Search input on unary operators (#19536)
* disable input on unary operators Signed-off-by: faissaloux <fwahabali@gmail.com> * use toggle instead of show/hide Signed-off-by: faissaloux <fwahabali@gmail.com> * lint Signed-off-by: faissaloux <fwahabali@gmail.com> --------- Signed-off-by: faissaloux <fwahabali@gmail.com>
1 parent 92a051e commit c97301c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

resources/js/src/table/select.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const checkIfDataTypeNumericOrDate = function (dataType) {
4444
const TableSelect = {
4545
checkIfDataTypeNumericOrDate: checkIfDataTypeNumericOrDate,
4646
};
47+
const UNARY_OPERATORS = [
48+
'IS NULL',
49+
'IS NOT NULL',
50+
'= \'\'',
51+
'!= \'\''
52+
];
53+
54+
const opIsUnary = (op) => UNARY_OPERATORS.includes(op);
4755

4856
/**
4957
* Unbind all event handlers before tearing down a page
@@ -282,7 +290,6 @@ AJAX.registerOnload('table/select.js', function () {
282290
* Ajax event handler for Range-Search.
283291
*/
284292
$('body').on('change', 'select[name*="criteriaColumnOperators"]', function () { // Fix for bug #13778, changed 'click' to 'change'
285-
var $sourceSelect = $(this);
286293
// Get the column name.
287294
var columnName = $(this)
288295
.closest('tr')
@@ -298,7 +305,11 @@ AJAX.registerOnload('table/select.js', function () {
298305
dataType = TableSelect.checkIfDataTypeNumericOrDate(dataType);
299306

300307
// Get the operator.
301-
var operator = ($(this).val() as string);
308+
const operator = ($(this).val() as string);
309+
const $targetField = $(this).closest('tr').find('[name*="criteriaValues"]')
310+
311+
$targetField.prop('disabled', opIsUnary(operator));
312+
$targetField.siblings('.ui-datepicker-trigger').eq(0).toggle(!opIsUnary(operator));
302313

303314
if ((operator === 'BETWEEN' || operator === 'NOT BETWEEN') && dataType) {
304315
var $msgbox = ajaxShowMessage();
@@ -345,9 +356,6 @@ AJAX.registerOnload('table/select.js', function () {
345356
maxValue;
346357
}
347358

348-
var $targetField = $sourceSelect.closest('tr')
349-
.find('[name*="criteriaValues"]');
350-
351359
// If target field is a select list.
352360
if ($targetField.is('select')) {
353361
$targetField.val(finalValue);

0 commit comments

Comments
 (0)