如何在用户忽略的jQuery自动完成建议检测 [英] How to detect when user ignores jquery autocomplete suggestions

查看:117
本文介绍了如何在用户忽略的jQuery自动完成建议检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要的能力,如果用户输入文本的没有的从一组自动完成建议选择调用处理程序。

We need the ability to call a handler if a user enters text without choosing from a set of autocomplete suggestions.

在我们的例子中,如果输入的文本相匹配的自动填充值与否并不重要 - 我们只关心如果用户点击/选择一个自动完成值,或不

In our case it doesn't matter if the entered text matches any autocomplete values or not - we only care if the user clicks/selects an autocomplete value, or not.

我们的表单的工作方式是,用户开始输入联系人的最后名称,并得到与自动完成建议,包括联系人的全名和公司psented $ P $。如果用户选择的自动完成建议之一,我们填入多个字段。这是所有工作的罚款。

The way our form works is that a user starts entering a contact's last-name and gets presented with autocomplete suggestions including the contact's full-name and company. If the user selects one of the autocomplete suggestions, we populate multiple fields. That's all working fine.

新的要求是,如果用户不选择的建议之一,我们需要头脑一片空白多个字段 - 这是我们希望使用的自动完成库调用处理程序实施

The new requirement is that if the user does NOT select one of the suggestions, we need to blank out multiple fields - which we'd like to implement using a handler called from an autocomplete library.

看着<一个href=\"http://stackoverflow.com/questions/328430/jquery-autocomplete-determining-if-entered-text-is-not-a-match\">$p$pvious <一href=\"http://stackoverflow.com/questions/797969/jquery-autocomplete-verify-selected-value\">answers,它看起来并不像我们能做到这与乔恩Zaefferer的自动完成插件的,但如果你有一个修补程序或一些想法如何实现的功能,这是我们想尝试并推到库中。

Looking at previous answers, it doesn't look like we can do this with Jörn Zaefferer's autocomplete plugin, but if you have a patch or some idea how to implement the function, this is the library we'd try and push it into.

推荐答案

我也碰到过很有意思的答案。它涉及的jQuery插件如何管理自己的地位。当我看着萤火虫(带firequery)我发现,当我点击图标显示DOM节点的jQuery的属性(HTML标签)它表现都连接到一个DOM节点和连接到该插件的数据是整个自动完成参数。因此,我找到了解决办法。

I have come across very interesting answer. It deals with how jQuery plugins manages their status. As I was looking at firebug(with firequery) I found that when I clicked icon showing jQuery properties of a DOM Node(in HTML tab) it showed all the plugin data attached to a DOM Node and attached to that was entire autocomplete parameters. Thus I found the solution.

$('#test').autocomplete({
    change:function( event, ui ) {
        var data=$.data(this);//Get plugin data for 'this'
        if(data.autocomplete.selectedItem==undefined)
            alert("manual");
        else
            alert("selected");      
    }
});

自动完成什么做的是,如果我们从列表中选择,然后将selectedItem包含我们只是它的所有属性中选择的JSON对象。但是,如果我们preSS ESC或取消设置为null自动填充。

What autocomplete does is that if we select from list then selectedItem contains the JSON object we just selected with all its properties. But if we press ESC or Cancel the autofill it is set to null.

这篇关于如何在用户忽略的jQuery自动完成建议检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆