Bug 30055: Force exact match for dropdown

For libraries and categories we need to use an exact match.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Séverine Queune <severine.queune@bulac.fr>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2022-02-17 09:26:02 +01:00 committed by Fridolin Somers
parent a4366b0b45
commit ca27beb752
2 changed files with 20 additions and 8 deletions

View file

@ -344,11 +344,11 @@
[% CASE 'branch' %]
let library_id = $("#branchcode_filter").val();
patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id);
table_dt.column([% loop.count - 1 %]).search(library_id);
table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : '');
[% CASE 'category' %]
let category_id = $("#categorycode_filter").val();
patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id);
table_dt.column([% loop.count - 1 %]).search(category_id);
table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : '');
[% END %]
[% END %]
table_dt.search("");

View file

@ -566,9 +566,14 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
for (var i=0;i<attributes.length;i++){
var part = {};
var attr = attributes[i];
part[!attr.includes('.')?'me.'+attr:attr] = options.criteria === 'exact'
let criteria = options.criteria;
if ( value.match(/^\^(.*)\$$/) ) {
value = value.replace(/^\^/, '').replace(/\$$/, '');
criteria = "exact";
}
part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact'
? value
: {like: (['contains', 'ends_with'].indexOf(options.criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(options.criteria) !== -1?'%':'')};
: {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')};
parts.push(part);
}
return parts;
@ -847,10 +852,17 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
$( input_type, this ).on( 'keyup change', function () {
if ( table_dt.column(i).search() !== this.value ) {
table_dt
.column(i)
.search( this.value )
.draw();
if ( input_type == "input" ) {
table_dt
.column(i)
.search( this.value )
.draw();
} else {
table_dt
.column(i)
.search( '^'+this.value+'$', true, false )
.draw();
}
}
} );
} else {