From f8300168a6188ab53c0723d3a1eb8813ceb46bf3 Mon Sep 17 00:00:00 2001 From: arabasso Date: Thu, 26 Jan 2023 11:02:17 -0300 Subject: [PATCH] Add accent insensitive filtering support. --- dist/js/bootstrap-multiselect.js | 6 ++++++ types/bootstrap-multiselect/index.d.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/dist/js/bootstrap-multiselect.js b/dist/js/bootstrap-multiselect.js index 7d88d8c4..ec747458 100644 --- a/dist/js/bootstrap-multiselect.js +++ b/dist/js/bootstrap-multiselect.js @@ -429,6 +429,7 @@ selectAllJustVisible: true, enableFiltering: false, enableCaseInsensitiveFiltering: false, + enableAccentInsensitiveFiltering: false, enableFullValueFiltering: false, enableClickableOptGroups: false, enableCollapsibleOptGroups: false, @@ -1260,6 +1261,11 @@ this.query = this.query.toLowerCase(); } + if (this.options.enableAccentInsensitiveFiltering) { + filterCandidate = filterCandidate.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); + this.query = this.query.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); + } + if (this.options.enableFullValueFiltering && this.options.filterBehavior !== 'both') { var valueToMatch = filterCandidate.trim().substring(0, this.query.length); if (this.query.indexOf(valueToMatch) > -1) { diff --git a/types/bootstrap-multiselect/index.d.ts b/types/bootstrap-multiselect/index.d.ts index 292a3854..2d8f6add 100644 --- a/types/bootstrap-multiselect/index.d.ts +++ b/types/bootstrap-multiselect/index.d.ts @@ -325,6 +325,12 @@ interface MultiSelectOptions { */ enableCaseInsensitiveFiltering?: boolean; + /** + * The filter as configured above will use accent sensitive filtering, + * by setting enableAccentInsensitiveFiltering to true this behavior can be changed to use accent insensitive filtering. + */ + enableAccentInsensitiveFiltering?: boolean; + /** * Set to true to enable full value filtering, that is all options are shown where the query is a prefix of. */