snapappointments / bootstrap-select

:rocket: The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more.
https://developer.snapappointments.com/bootstrap-select/
MIT License
9.84k stars 2.72k forks source link

Psuedo pull request: Always select the first startsWith match if found #1078

Open Tsaukpaetra opened 9 years ago

Tsaukpaetra commented 9 years ago

Referring #1076 , I have no idea how to do a pull request, but the following code replaces lines 1252-1253 in bootstrap-select.js (the end lines of the function this.$searchbox.on('input propertychange', function () ) It should effectively select the first matched item (if found), case insensitive, when performing a live search, while still allowing all the other selection functionality.

    var foundItem;
    if (that.options.liveSearchNormalize) {
        foundItem = that.$lis.filter(':aibegins(' + normalizeToBase(that.$searchbox.val()) + ')')[0];
    } else {
        foundItem = that.$lis.filter(':ibegins(' + that.$searchbox.val() + ')')[0];
    }
    if (typeof foundItem != "undefined") {
        //find the index of the match
        var foundItemIndex = that.$lis.index(foundItem);
        //Select the match!
        $(this).parent().data('prevIndex', foundItemIndex);
        that.$lis.removeClass('active').eq(foundItemIndex).addClass('active').children('a').focus();
    } else {
        //Adjust the active selector if nothing (visible) is active
        if (that.$lis.not('.hidden, .divider, .dropdown-header').filter('.active').length == 0) {
            that.$lis.filter('.active').removeClass('active');
            //Activate the top-most visible option
            that.$lis.not('.hidden, .divider, .dropdown-header').eq(0).addClass('active').children('a').focus();
        }
    }
jtfairbank commented 8 years ago

Forking a repo: https://help.github.com/articles/fork-a-repo/

Making a pull request: https://help.github.com/articles/using-pull-requests/

Do you need help with git as well? :)