Merge #16666 - Fix #16424 - Numerical search in table and zoom

Pull-request: #16666
Fixes: #16424

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-02-18 20:19:24 +01:00
commit 4df8cd0b3c
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
5 changed files with 42 additions and 9 deletions

View File

@ -152,15 +152,26 @@ function checkForCheckbox (multiEdit) {
// eslint-disable-next-line no-unused-vars
function verifyAfterSearchFieldChange (index, searchFormId) {
var $thisInput = $('input[name=\'criteriaValues[' + index + ']\']');
// Add data-skip-validators attribute to skip validation in changeValueFieldType function
if ($('#fieldID_' + index).data('data-skip-validators')) {
$(searchFormId).validate().destroy();
return;
}
// validation for integer type
if ($thisInput.data('type') === 'INT') {
if ($thisInput.data('type') === 'INT' ||
$thisInput.data('type') === 'TINYINT') {
// Trim spaces if it's an integer
$thisInput.val($thisInput.val().trim());
var hasMultiple = $thisInput.prop('multiple');
if (hasMultiple) {
$(searchFormId).validate();
$(searchFormId).validate({
// update errors as we write
onkeyup: function (element) {
$(element).valid();
}
});
// validator method for IN(...), NOT IN(...)
// BETWEEN and NOT BETWEEN
jQuery.validator.addMethod('validationFunctionForMultipleInt', function (value) {
@ -170,9 +181,16 @@ function verifyAfterSearchFieldChange (index, searchFormId) {
);
validateMultipleIntField($thisInput, true);
} else {
$(searchFormId).validate();
$(searchFormId).validate({
// update errors as we write
onkeyup: function (element) {
$(element).valid();
}
});
validateIntField($thisInput, true);
}
// Update error on dropdown change
$thisInput.valid();
}
}
@ -205,6 +223,9 @@ function validateMultipleIntField (jqueryInput, returnValueIfFine) {
function validateIntField (jqueryInput, returnValueIfIsNumber) {
var mini = parseInt(jqueryInput.data('min'));
var maxi = parseInt(jqueryInput.data('max'));
// removing previous rules
jqueryInput.rules('remove');
jqueryInput.rules('add', {
number: {
param: true,
@ -797,8 +818,18 @@ function changeValueFieldType (elem, searchIndex) {
if (0 === fieldsValue.size()) {
return;
}
var type = $(elem).val();
if ('LIKE' === type ||
'LIKE %...%' === type ||
'NOT LIKE' === type
) {
$('#fieldID_' + searchIndex).data('data-skip-validators', true);
return;
} else {
$('#fieldID_' + searchIndex).data('data-skip-validators', false);
}
if ('IN (...)' === type ||
'NOT IN (...)' === type ||
'BETWEEN' === type ||

View File

@ -5,7 +5,7 @@
* @requires js/functions.js
*/
/* global changeValueFieldType */ // js/table/change.js
/* global changeValueFieldType, verifyAfterSearchFieldChange */ // js/table/change.js
/* global openGISEditor, gisEditorLoaded, loadJSAndGISEditor, loadGISEditor */ // js/gis_data_editor.js
var TableSelect = {};
@ -81,6 +81,7 @@ AJAX.registerOnload('table/select.js', function () {
$.each(tableRows, function (index, item) {
$(item).on('change', function () {
changeValueFieldType(this, index);
verifyAfterSearchFieldChange(index, '#tbl_search_form');
});
});

View File

@ -6,6 +6,7 @@
** @requires js/functions.js
**/
/* global changeValueFieldType, verifyAfterSearchFieldChange */ // js/table/change.js
/**
** Display Help/Info
@ -133,8 +134,8 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', 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);
verifyAfterSearchFieldChange(index, '#zoom_search_form');
});
});
};

View File

@ -412,7 +412,7 @@ class SearchController extends AbstractController
. 'data-max="' . $minMaxValues[1] . '"';
}
$htmlAttributes .= ' onchange="return '
$htmlAttributes .= ' onfocus="return '
. 'verifyAfterSearchFieldChange(' . $column_index . ', \'#tbl_search_form\')"';
$value = $this->template->render('table/search/input_box', [

View File

@ -468,8 +468,8 @@ class ZoomSearchController extends AbstractController
. 'data-max="' . $minMaxValues[1] . '"';
}
$htmlAttributes .= ' onchange="return '
. 'verifyAfterSearchFieldChange(' . $column_index . ', \'#zoom_search_form\')"';
$htmlAttributes .= ' onfocus="return '
. 'verifyAfterSearchFieldChange(' . $search_index . ', \'#zoom_search_form\')"';
$value = $this->template->render('table/search/input_box', [
'str' => '',