Search code examples
jquerybootstrap-multiselect

jquery bootstrap-multiselect, search using non consecutive words


Is it possible to modify https://github.com/davidstutz/bootstrap-multiselect search functionality to search using non consecutive multiple words?

For example in the following, they want show all options that have "one" and "two" by searching using "one two"

1) One and Two
2) Two and One
3) Blue
4) Green and Blue

The result should show 1) and 2)


Solution

  • recommended to use special characters like ; in the 1070 line:

    var queryValues = this.query.split(";");
    for(var i = 0;i<queryValues.length;i++){
    queryValues[i].trim();
    if (this.options.enableFullValueFiltering && this.options.filterBehavior !== 'both') {
            var valueToMatch = filterCandidate.trim().substring(0, queryValues[i].length);
            if (queryValues[i].indexOf(valueToMatch) > -1) {
                showElement = true;
                break;
            }
        }
        else if (filterCandidate.indexOf(queryValues[i]) > -1) {
            showElement = true;
            break;
        }
    }
    

    I fork a branch https://github.com/catzaizai/bootstrap-multiselect