自动完成键UP / DOWN行为

时间:2011-12-22 08:04:49

标签: jquery jquery-autocomplete

我正在使用jQuery的自动完成插件。我已经修改了这个,以便在复选框的帮助下从结果菜单中支持多项选择。对我来说,自动填充框中的值只应在用户单击复选框时更新。

  1. 当鼠标悬停在结果菜单上时,自动填充文本框中的值不会更新。 - 默认行为。
  2. 当使用键UP / DOWN导航搜索结果时,相应的行(聚焦的一个)值将被更新。我通过从焦点函数返回false来克服这一点。
  3. 有问题的情况 - 用户使用鼠标选择了一行,然后在自动填充的文本框中更新了相应的行值。在此用户使用向上/向下键导航结果后,自动填充文本框中的值将被使用键UP / DOWN当前处于焦点的行的值替换。
  4. I have uploaded an image explaining the same

    在图像中,以“红色”突出显示的行表示使用鼠标选择的行,而在“黄色”中突出显示的行是由于键DOWN而在焦点上的当前行。

    让我知道如何实现这一点。

     $("#name")
    .keydown(function(event) 
    {
            //code for highlighting
        } 
     ).autocomplete({
        minLength: 2,
        multiple: true,
        source: function(request,response)
        {
            //fetch required data, format: [{name:" ", id: " "},{name:" ", id: " "}]
        },
        select: function(event,ui)
        {
            var terms = split( this.value );
            terms.pop();
            terms.push( ui.item.value);
            terms.push( "" );
            this.value = terms.join( " ," );
            return false;
        },
        focus: function(event,ui)
        {
           return false;
        }
     }).data("autocomplete")._renderMenu = function(menuUI,items)
     {
        //change the rendering to display checkbox for each result.
        //on clicking on the checkbox, its value will be appended to autocomplete's textbox
     };
     });
    

0 个答案:

没有答案
相关问题