使用虚拟键盘与jQuery UI自动完成

时间:2013-06-06 13:20:27

标签: jquery autocomplete keyboard virtual

经过多日的努力并搜索各种论坛后,我会在这里试一试。

我无法使用Mottie虚拟键盘(https://github.com/Mottie/Keyboard)使用jQuery UI自动完成小部件。 只要您使用物理键盘,带有ajax加载值的jQuery自动完成功能就可以正常工作。 如果我通过虚拟键盘输入2个字符,我会看到这些字符,但没有自动完成列表。如果我在物理键盘上输入第三个字符,则显示第一个列表。因此,物理输入数据正确附加到虚拟输入数据。 试图省略Ajax部分并使用一些简单的单词作为测试,相同的行为。 检查IE,Firefox,Chrome:都一样。 同时通过鼠标从自动完成列表中选择一个值也不起作用。

任何人都解决了这个并创建了一个工作示例?

这是我的测试代码:

<... load jQuery, virtual keyboard, CSS etc...>
<script>
    $(document).ready(function() {
        $(function() {
            function log(message) {
                $("<div>").text(message).prependTo("#log");
                $("#log").scrollTop(0);
            }
            $('#sometext').keyboard({
                usePreview: false,
                position: {at: 'right bottom', of: '#log'}
            }).autocomplete({
                source: ['One', 'Two', 'Three', 'Musketiers'],
                minLength: 1,
                select: function(event, ui) {
                    if (ui.item) {
                        log("Selected: " + ui.item.label);
                    }
                }
            }).addAutocomplete();
        });
    });
</script>

<div class="ui-widget">
    <label for="sometext">Some label: </label>
    <input id="sometext" />
</div>
<div class="ui-widget" style="margin-top: 2em; font-family: Arial;">
    <div id="log" style="height: 50px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>

更新: 看起来Mottie Virtual键盘找不到jQuery自动完成功能。在源头(第88行),它说:

// set up after keyboard is visible
base.autocomplete_setup = function() {
    // look for autocomplete
    base.$autocomplete = base.$el.data('autocomplete');
    base.hasAutocomplete = (typeof(base.$autocomplete) === 'undefined') ? false : (base.$autocomplete.options.disabled) ? false : true;

'base.hasAutocomplete'原来是假的

1 个答案:

答案 0 :(得分:2)

此问题已在较新版本的jquery.keyboard.extension-autocomplete.js中解决。

根据this检查JQuery-UI版本的自动完成代码与JQuery-UI版本1.10有问题 以下更改在jquery.keyboard.extension-autocomplete.js中进行:

base.$autocomplete = base.$el.data('autocomplete'); //removed
base.$autocomplete = base.$el.data('autocomplete') || base.$el.data('uiAutocomplete'); //added