Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example page bug #276

Closed
artknight opened this issue Mar 3, 2015 · 4 comments
Closed

example page bug #276

artknight opened this issue Mar 3, 2015 · 4 comments

Comments

@artknight
Copy link

When using "searchable" example, arrow keys (up/down) are not working.

Please fix.

Thanks,

@Robdel12
Copy link
Owner

Robdel12 commented Mar 4, 2015

Do you mean when you open the select you can use arrow keys? I'm not sure how to get around that still give the input focus.

@Robdel12 Robdel12 removed the Minor bug label Mar 4, 2015
@artknight
Copy link
Author

I think it would be OK if the input looses focus when the user is stepping through the results. So, basically it would a likely scenario that initially the user used the input to narrow down the result set, and then used the arrow keys to get down to the desired entry.

@artknight
Copy link
Author

Anyways, In the meantime I have implemented a temporary solution. Here is the code below. Let me know if you come up with a better way. Thanks!

$.extend($.fn,{
searchDropdown: function(options){
var options = _.extend({},options),
keys = { UP:38, DOWN:40 };

    //must add .search-select class for proper styling
    this.addClass('search-select');

    return this.dropkick({
        mobile: true,
        initialize: function(){
            var $input,
                dk = this;

                dk.temp = {
                    found: dk.options,
                    lastSelectedIndex: dk.selectedIndex || 0
                };

            $('.dk-selected',dk.data.elem).after('<div class="dk-search"><input type="text" class="dk-search-input" placeholder="Search"></div>');
            $input = $('.dk-search-input',dk.data.elem);
            $input.on("click",function(event){
                event.stopPropagation();
            }).on('keypress keyup', function(event){
                event.stopPropagation();
                var keyCode = UTILS.getCharKey(event);

                if (keyCode===keys.UP){
                    dk.temp.lastSelectedIndex--;
                    (dk.temp.lastSelectedIndex < 0) && (dk.temp.lastSelectedIndex = 0);
                    dk.selectOne(dk.temp.found[dk.temp.lastSelectedIndex]);
                }
                else if (keyCode===keys.DOWN){
                    dk.temp.lastSelectedIndex++;
                    (dk.temp.lastSelectedIndex > dk.temp.found.length-1) && (dk.temp.lastSelectedIndex = dk.temp.found.length-1);
                    dk.selectOne(dk.temp.found[dk.temp.lastSelectedIndex]);
                }
                else {
                    dk.temp.found = dk.search(this.value, dk.data.settings.search);
                    dk.temp.lastSelectedIndex = 0;

                    $('.dk-option', dk.data.elem).remove();
                    if (dk.temp.found.length){
                        $(dk.temp.found).appendTo(dk.data.elem.lastChild);
                        dk.selectOne(dk.temp.found[0]);
                    }
                    else
                        $('<li></li>').addClass('dk-option dk-option-disabled').text('Not Found').appendTo(dk.data.elem.lastChild);
                }
            });
            ('selectedValue' in options) && dk.select(options.selectedValue);
        },
        search: options.search || 'strict',
        open: function(){
            $('.dk-search-input',this.data.elem).focus();
            ('open' in options) && options.open.call(this);
        },
        close: function(){
            $('.dk-search-input',this.data.elem).val("").blur();
            $('.dk-option',this.data.elem).remove();
            $(this.options).appendTo(this.data.elem.lastChild);
            ('close' in options) && options.close.call(this);
        },
        change: ('change' in options) ? options.change : new Function
    });
}

});

@Robdel12
Copy link
Owner

Robdel12 commented Mar 5, 2015

Ah, so I was afraid this was going to happen, and this is totally our fault. The search select on our example page is purely to show off the power of our API. It's not an official DK select.

So I think what we're going to do is remove that select from the example page and bring it back when I complete #274 with better messaging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants