使用JQuery虚拟键盘和Select2

时间:2018-06-13 19:36:59

标签: jquery jquery-select2 virtual-keyboard

我正在使用jQuery MLKeyboard在网站上显示虚拟键盘。

我尝试使用此代码来防止下拉关闭事件,并在触发选定事件时关闭布尔标志,但它会保持打开状态。此外,当我单击虚拟键盘上的字母时,select2下拉菜单将关闭。

另外,我使用ajax请求搜索select2字段,但它不会更新结果。

我已经看过像这样的帖子,没有回答:

Using select2 with a jQuery Virtual Keyboard?

这是代码:

$('#streetAutocomplete').select2({ 
    theme: 'bootstrap',
    placeholder: Resources.SelectStreet,
    minimumInputLength: 0,
    allowClear: true,
    ajax: {
        //How long the user has to pause their typing before sending the next request 
        quietMillis: 150,
        debug: true,
        //The url of the json service 
        url: '/Home/Autocomplete', 
        dataType: 'json', 
        //Our search term and what page we are on 
        data: function (term) {
            return {
                searchTerm: term 
                }
            }, 
            processResults: function (data) {
                return { 
                    results: data.Results 
                }; 
            } 
    } 
}); 

$(".select2-search, .select2-focusser").remove(); 
$('#streetAutocomplete').on('select2:closing', function (e) {
    e.preventDefault(); 
}); 

$('#streetAutocomplete').on('select2:closed', function () { 
    if (!selectedStreet) {
        $('#streetAutocomplete').select2("open"); 
    } 
}); 

$('#streetAutocomplete').on('select2:select', function () { 
    $('#setStreetConfirm').prop("disabled", false); 
    selectedStreet = true; 
    $('#streetAutocomplete').select2('close'); 
}); 

$('#streetAutocomplete').on('select2:open', function () { 
    $('#setStreetConfirm').prop("disabled", true); 
    selectedStreet = false; 
    $('.select2-search__field').mlKeyboard({ layout: 'es_ES', active_shift: false }); 
});

任何帮助将不胜感激。谢谢

0 个答案:

没有答案