Reply To: Multi-select Enhanced select – disable exact match

Home Forums Quform WordPress Multi-select Enhanced select – disable exact match Reply To: Multi-select Enhanced select – disable exact match

#35290
amplastic
Participant

i got chatgpt to code it for me 🙂

jQuery(function ($) {
function containsAllWords(words, text) {
for (var i = 0; i < words.length; i++) {
if (text.toLowerCase().indexOf(words[i].toLowerCase()) === -1) {
return false;
}
}
return true;
}

$(‘.quform-field-multiselect-enhanced’).each(function () {
var $select = $(this),
options = $select.data(‘options’),
config = {
theme: ‘quform’,
language: {
noResults: function () {
return options.noResultsFound;
}
},
matcher: function(params, data) {
// If there are no search terms, return all of the data
if ($.trim(params.term) === ”) {
return data;
}

// Do not display the item if there is no ‘text’ property
if (typeof data.text === ‘undefined’) {
return null;
}

// params.term should be the term that is used for searching
// data.text is the text that is displayed for the data object
var words = params.term.trim().toLowerCase().split(/\s+/);
if (containsAllWords(words, data.text.toLowerCase())) {
var modifiedData = $.extend({}, data, true);

// You can return modified objects from here
// This includes matching the children how you want in nested data sets
return modifiedData;
}

// Return null if the term should not be displayed
return null;
}
};

if (Quform.isNonEmptyString(options.placeholder)) {
config.placeholder = options.placeholder;
}

if (options.rtl) {
config.dir = ‘rtl’;
}

$select.select2(‘destroy’).select2(config);
});
});

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy