peledies/select2-tab-fix

Problem when the tab order doesn't follow the DOM order

Opened this issue · 0 comments

This is a great bit of code, and I'm really glad to have found it. It did almost everything I wanted it to, but because my tab order is quite different to the order of elements in the DOM, it was moving away from my required tab order. I included this bit of code before your current line 83 (the bit where you decide which direction you're going to move):

inputs.sort(function(a, b) {
    var aVal = a.tabIndex;
    var bVal = b.tabIndex;
    if (a.tagName == 'SELECT' && a.tabIndex == -1) {
        var aParent = $('#select2-' + a.id + '-container').parent();
        aVal = parseInt(aParent.attr("tabindex"));
    }
    if (b.tagName == 'SELECT' && b.tabIndex == -1) {
        var bParent = $('#select2-' + b.id + '-container').parent();
        bVal = parseInt(bParent.attr("tabindex"));
    }
    return aVal - bVal;
});

It may be horribly inefficient, but it does the job for me.