自动完成停止当用户presses" Enter]键。 [英] AutoComplete Stopping When User Presses "Enter"

查看:261
本文介绍了自动完成停止当用户presses" Enter]键。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个商业网站的AutoCompleteExtender。我的问题是用户正在迅速键入一个单词的一部分,并立即pressing输入,这将导致自动完成控制的的带回来的建议列表。例如,如果我的数据库中有一句德克萨斯州,美国中,但用户只需键入得克萨斯紧接着进入再下拉列表中不会出现。

I am using the AutoCompleteExtender on a commercial site. My problem is the users are quickly typing in part of a word and immediately pressing "Enter" which causes the AutoComplete control to NOT come back with a list of suggestions. For example, if my database has the phrase "Texas, United States" in it but the users just type "Texas" quickly followed by Enter then the dropdown list does not appear.

我想是自动完成控制,忽略用户拥有pressed进入去反正获取建议的数据事实。 (最终将是,如果它忽略了输入时,有目前没有名单,但是当有一个列表中选择一个项目)。

What I would like is for the AutoComplete control to ignore the fact the user has pressed Enter and go and fetch the suggested data anyway. (The ultimate would be if it ignored Enter when there was currently no list, but selected an item when there was a list).

我可以去一些字符很快其次是确认此Microsoft ASP.NET网站和打字的样品部分模拟这一确切的问题。

I can simulate this exact problem by going to the samples section of this Microsoft ASP.NET site and typing in some characters very quickly followed by 'Enter'.

请会有人告诉我,我需要做什么?

Please could someone tell me what I need to do?

谢谢,马丁

推荐答案

我解决此问题砍死上,它是自动完成的目标文本框的额外的keydown处理程序之前。在下面与您AutoCompleteBehavior(获得的实例的引用代码段替换 this._autoCompleteBehavior 通过 $找到()和在 BehaviorID )。这里的想法是给力的自动完成行为,认为它需要通过调用执行查找 _onTimerTick(),其中打字延迟期满后执行。默认情况下,打字延迟被通过敲击回车键取消了,所以这只是强制查找反正上输入或选项卡。

I've hacked around this problem before with an extra keydown handler on the textbox that is the target of the auto-complete. Replace this._autoCompleteBehavior in the snippet below with a reference to your instance of AutoCompleteBehavior (obtainable via $find() and the BehaviorID). The idea here is to force the auto-complete behavior to think it needs to perform a lookup by calling _onTimerTick(), which executes after the typing delay has expired. By default the typing delay gets cancelled by hitting the enter key, so this just forces the lookup anyway on enter or tab.

免责声明:我劈引用AjaxControlToolkit code的私有成员(的东西,用下划线开头是私人),所以它可能不能保证是面向未来的。

Disclaimer: my hack references "private" members of the AjaxControlToolkit code (stuff that starts with underscore is "private"), so it is probably not guaranteed to be future-proof.

_searchTextbox_keydown: function(e)
{
    var key = e.keyCode || e.rawEvent.keyCode;

    // If the user hits enter or tab before the auto complete popup appears, force the autocomplete lookup at that moment.        
    if ((key === Sys.UI.Key.enter || key === Sys.UI.Key.tab) && this._autoCompleteBehavior._currentPrefix != this._autoCompleteBehavior._currentCompletionWord())
    {
        this._autoCompleteBehavior._onTimerTick(this._autoCompleteBehavior._timer, Sys.EventArgs.Empty);

        e.preventDefault();
    }
}

这篇关于自动完成停止当用户presses" Enter]键。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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