From b1f07042c41f4014edc6ea3dd4f14e10d24607b3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 14 Jul 2022 08:24:12 +0100 Subject: [PATCH] Bug 31028: Add 'special:undefined' to handle passing 'null' We can't pass 'null' to the column.search as it gets stringified. This patch adds a special string 'special:undefined' to denote that we want to search on undef for the field in question. --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index a22d5dd4d5..4b35198344 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -584,12 +584,18 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { var part = {}; var attr = attributes[i]; let criteria = options.criteria; - if ( value.match(/^\^(.*)\$$/) ) { - value = value.replace(/^\^/, '').replace(/\$$/, ''); + if ( value === 'special:undefined' ) { + value = null; criteria = "exact"; - } else { - // escape SQL LIKE special characters % and _ - value = value.replace(/(\%|\_|\\)/g, "\\$1"); + } + if ( value !== null ) { + if ( value.match(/^\^(.*)\$$/) ) { + value = value.replace(/^\^/, '').replace(/\$$/, ''); + criteria = "exact"; + } else { + // escape SQL LIKE special characters % and _ + value = value.replace(/(\%|\_|\\)/g, "\\$1"); + } } part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact' ? value -- 2.20.1