关闭Typeahead.js的标签 [英] Turn Off Tab for Typeahead.js

查看:48
本文介绍了关闭Typeahead.js的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个文本框中使用了typeahead( typeahead.js ),而我正在尝试关闭制表自动完成功能.我在文档中找不到此消息,但也许有人知道这是否可行?

I am using a typeahead on one of my text boxes(typeahead.js), and I am trying to turn off the tabbing auto complete. I couldn't find this in the documentation, but perhaps someone knows if/how this is possible?

有什么建议吗?

用于插入的代码:

myTypeAhead = $('#txtTypeAhead').typeahead({
            name: 'TypeAhead',
            valueKey: "Value",
            remote: '/ServiceHandlers/myHandler.ashx?Method=Method&Query=%QUERY',
            template: ['<p>{{Value}}</p>'],
            engine: Hogan
        });


        companyCodeTypeAhead.on('typeahead:initialized', function (evt)
        {
            console.log('INIT ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:opened', function (evt)
        {
            console.log('OPEN ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:closed', function (evt)
        {
            console.log('CLOSE ' + $(evt.target).val());
        });
        companyCodeTypeAhead.on('typeahead:selected', function (evt, data)
        {
            console.log('SELECT data==>' + data.Key + ' - ' + data.Value); //selected datum object
        });
        companyCodeTypeAhead.on('typeahead:autocompleted', function (evt, data)
        {
            console.log('AUTOCOMPLETE data==>' + data.Key + ' - ' + data.Value); //selected datum object
        });

推荐答案

在typeahead 0.11.1中,它是15年12月9日发布的版本:

In typeahead 0.11.1, which is the released version as of 12/9/15:

找到以下功能并注释掉自动完成行,如图所示并添加下一行,该行模拟转义键的行为会引发正确的事件,但需要使用 $ e.preventDefault(); 来防止浏览器绕过Tab键的拦截提前输入的逻辑.

Locate the following function and comment out the autocomplete line as shown and add the next line, which simulates the escape key behavior causing the right events to be thrown, but needs to have $e.preventDefault(); to prevent the interception of the tab key by the browser bypassing typeahead's logic.

        _onTabKeyed: function onTabKeyed(type, $e) {
            var $selectable;
            if ($selectable = this.menu.getActiveSelectable()) {
                this.select($selectable) && $e.preventDefault();
            } else if ($selectable = this.menu.getTopSelectable()) {
//              this.autocomplete($selectable) && $e.preventDefault(); // <-- Comment out
                this.close() && $e.preventDefault();  // <--- Add this
            }
        },

希望他们将在即将发布的版本中对此进行配置.

Hopefully they will make that configurable in a forthcoming release.

这篇关于关闭Typeahead.js的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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