From 74ca037b6970187db39c8ff1b221381217247af8 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 fb55a9b271..97f60c974e 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 % + value = value.replace(/(\%|\\)/g, "\\$1"); + } } part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact' ? value -- 2.20.1