From bc7ea6c09686a771120eb3887c1e329fbe9289d3 Mon Sep 17 00:00:00 2001 From: Neaox Date: Fri, 4 Dec 2015 08:50:30 +1300 Subject: [PATCH] [Dropdown] Allow ignoring of case when getting an item Currently get.item compares labels and values case sensitively. This can cause duplicates when `allowAdditions` is `true`. To prevent these duplicates get.item should be capable of comparing labels and values while ignoring case. However the current behaviour should be preserved by default. To achieve this a new setting is added called `ignoresCase`, which when `true` will disregard the casing of labels and string values when performing the comparision. --- src/definitions/modules/dropdown.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/definitions/modules/dropdown.js b/src/definitions/modules/dropdown.js index be153d30e..b24ab79c9 100644 --- a/src/definitions/modules/dropdown.js +++ b/src/definitions/modules/dropdown.js @@ -1677,6 +1677,10 @@ $.fn.dropdown = function(parameters) { ? module.get.values() : module.get.text() ; + value = (typeof value === "string" && settings.ignoresCase) + ? value.toLowerCase() + : value + ; shouldSearch = (isMultiple) ? (value.length > 0) : (value !== undefined && value !== null) @@ -1694,6 +1698,14 @@ $.fn.dropdown = function(parameters) { optionText = module.get.choiceText($choice), optionValue = module.get.choiceValue($choice, optionText) ; + optionText = (typeof optionText === "string" && settings.ignoresCase) + ? optionText.toLowerCase() + : optionText + ; + optionValue = (typeof optionValue === "string" && settings.ignoresCase) + ? optionValue.toLowerCase() + : optionValue + ; // safe early exit if(optionValue === null || optionValue === undefined) { return; @@ -3255,6 +3267,8 @@ $.fn.dropdown.settings = { duration : 200, // duration of transition glyphWidth : 1.0714, // widest glyph width in em (W is 1.0714 em) used to calculate multiselect input width + + ignoresCase : false, // when determining if an item exists or not ignore case of value and label when comparing // label settings on multi-select label: {