From 69d49789cec236010679a3e2b48421c5033bebc0 Mon Sep 17 00:00:00 2001 From: Ankush Patil Date: Sun, 5 Jul 2020 22:04:49 +0530 Subject: [PATCH] Fixes #16248: identifying searchType in validation function Signed-off-by: Ankush Patil --- js/table/change.js | 7 ++++--- js/table/zoom_plot_jqplot.js | 15 +++++++++++++++ .../Controllers/Table/SearchController.php | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/js/table/change.js b/js/table/change.js index 5c3b597cd8..6da6d26bb0 100644 --- a/js/table/change.js +++ b/js/table/change.js @@ -151,7 +151,7 @@ function checkForCheckbox (multiEdit) { // used in Search page mostly for INT fields // eslint-disable-next-line no-unused-vars -function verifyAfterSearchFieldChange (index) { +function verifyAfterSearchFieldChange (index, searchFormId) { var $thisInput = $('input[name=\'criteriaValues[' + index + ']\']'); // validation for integer type if ($thisInput.data('type') === 'INT') { @@ -159,8 +159,9 @@ function verifyAfterSearchFieldChange (index) { $thisInput.val($thisInput.val().trim()); var hasMultiple = $thisInput.prop('multiple'); + if (hasMultiple) { - $('#tbl_search_form').validate(); + $(searchFormId).validate(); // validator method for IN(...), NOT IN(...) // BETWEEN and NOT BETWEEN jQuery.validator.addMethod('validationFunctionForMultipleInt', function (value) { @@ -170,7 +171,7 @@ function verifyAfterSearchFieldChange (index) { ); validateMultipleIntField($thisInput, true); } else { - $('#tbl_search_form').validate(); + $(searchFormId).validate(); validateIntField($thisInput, true); } } diff --git a/js/table/zoom_plot_jqplot.js b/js/table/zoom_plot_jqplot.js index 659e6a7cef..7d07db6d62 100644 --- a/js/table/zoom_plot_jqplot.js +++ b/js/table/zoom_plot_jqplot.js @@ -129,6 +129,17 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () { searchedData = null; } + // adding event listener on select after AJAX request + var comparisonOperatorOnChange = function () { + var tableRows = $('#inputSection select.column-operator'); + $.each(tableRows, function (index, item) { + $(item).on('change', function () { + // eslint-disable-next-line no-undef + changeValueFieldType(this, index); + }); + }); + }; + /** ** Input form submit on field change **/ @@ -153,6 +164,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () { $('#types_0').val(data.field_type); xType = data.field_type; $('#collations_0').val(data.field_collations); + comparisonOperatorOnChange(); Functions.addDateTimePicker(); }); }); @@ -177,6 +189,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () { $('#types_1').val(data.field_type); yType = data.field_type; $('#collations_1').val(data.field_collations); + comparisonOperatorOnChange(); Functions.addDateTimePicker(); }); }); @@ -198,6 +211,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () { $('#tableFieldsId').find('tr:eq(4) td:eq(3)').html(data.field_value); $('#types_2').val(data.field_type); $('#collations_2').val(data.field_collations); + comparisonOperatorOnChange(); Functions.addDateTimePicker(); }); }); @@ -219,6 +233,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () { $('#tableFieldsId').find('tr:eq(5) td:eq(3)').html(data.field_value); $('#types_3').val(data.field_type); $('#collations_3').val(data.field_collations); + comparisonOperatorOnChange(); Functions.addDateTimePicker(); }); }); diff --git a/libraries/classes/Controllers/Table/SearchController.php b/libraries/classes/Controllers/Table/SearchController.php index c55f920a21..dbeee5fd6c 100644 --- a/libraries/classes/Controllers/Table/SearchController.php +++ b/libraries/classes/Controllers/Table/SearchController.php @@ -979,7 +979,9 @@ class SearchController extends AbstractController $type = 'INT'; } - $html_attributes .= " onchange= 'return verifyAfterSearchFieldChange(" . $column_index . ")'"; + $searchFormId = $this->_searchType === 'zoom' ? '#zoom_search_form' : '#tbl_search_form'; + + $html_attributes .= ' onchange="return verifyAfterSearchFieldChange(' . $column_index . ', \'' . $searchFormId . '\')"'; $value = $this->template->render('table/search/input_box', [ 'str' => '',