Home › Forums › Quform WordPress › Multi-select Enhanced select – disable exact match
- This topic has 4 replies, 2 voices, and was last updated 1 year, 8 months ago by Ally.
- AuthorPosts
- March 23, 2023 at 7:16 pm #35278amplasticParticipant
I have a mult-select field with “enable enhanced select” turned on. When I start typing into this field, options will only show if the search term is an exact match. However, I want options to come up without it exactly matching in same order as terms. How can I accomplish this?
Attachments:
You must be logged in to view attached files.March 24, 2023 at 3:01 pm #35284AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
March 24, 2023 at 4:14 pm #35286amplasticParticipantnow it displays results it shouldn’t. it seems to be searching for the letters within the words i type? I want it to search for the exact words i type in but doesn’t have to be in the exact order that i type the words in
- This reply was modified 1 year, 8 months ago by amplastic.
- This reply was modified 1 year, 8 months ago by amplastic.
Attachments:
You must be logged in to view attached files.March 24, 2023 at 4:36 pm #35290amplasticParticipanti 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 thechildren
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);
});
});March 27, 2023 at 9:56 am #35294AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.