JqueryUI自动完成自动聚焦覆盖我的文本输入

时间:2021-07-11 12:49:51

I am using the latest version of JqueryUI autocomplete(1.8.23). I am using autoFocus : true property and this is giving me a big problem.

我使用的是最新版本的JqueryUI自动完成(1.8.23)。我正在使用autoFocus:true属性,这给了我一个大问题。

When I start typing text in my input box at a somewhat quick pace, the autoFocus : true causes the text to be replaced with value from previous matches.

当我开始以稍微快的速度在输入框中键入文本时,autoFocus:true会导致文本被以前匹配的值替换。

eg: when I type "foot", this fires a request to the server and the first selection in the autocomplete dropdown becomes "foot", whereas I would have quickly continued to type "football". This replaces the letters ball as I type them.

例如:当我输入“foot”时,这会向服务器发出一个请求,并且自动完成下拉列表中的第一个选择变为“foot”,而我会很快继续输入“football”。当我输入它时,这将取代字母球。

Anybody faced this and found a solution?

任何人都面临这个并找到了解决方案?

UPDATE

This is a bug raised on the jquery ui site. Though it has been closed as fixed, it is not available in their latest stable version available for download. http://bugs.jqueryui.com/ticket/7555

这是jquery ui网站上提出的错误。虽然它已经被修复关闭,但它没有最新的稳定版本可供下载。 http://bugs.jqueryui.com/ticket/7555

If someone has found a workaround for this solution, would be great if you can share it.

如果有人找到了此解决方案的解决方法,那么如果您可以共享它会很棒。

1 个解决方案

#1


1  

Though the bug has been closed as "fixed" by the JQueryUI team, the fix is shown to be available only in 1.9.0 release. So until then, this is a workaround to the problem. The blur event is the cause of this problem.

虽然该错误已被JQueryUI团队“修复”关闭,但该修复程序仅在1.9.0版本中可用。所以在那之前,这是解决问题的方法。模糊事件是导致此问题的原因。

Add the following piece of code to your page's javascript:

将以下代码添加到页面的javascript中:

$('.ui-autocomplete-input').each(function (idx, elem) {
      var autocomplete = $(elem).data('autocomplete');
      if ('undefined' !== typeof autocomplete) {
            var blur = autocomplete.menu.options.blur;
            autocomplete.menu.options.blur = function (evt, ui) {
                  if (autocomplete.pending === 0) {
                        blur.apply(this,  arguments);
                  }
             };
      }
 });

Credit goes to these folks

归功于这些人

#1


1  

Though the bug has been closed as "fixed" by the JQueryUI team, the fix is shown to be available only in 1.9.0 release. So until then, this is a workaround to the problem. The blur event is the cause of this problem.

虽然该错误已被JQueryUI团队“修复”关闭,但该修复程序仅在1.9.0版本中可用。所以在那之前,这是解决问题的方法。模糊事件是导致此问题的原因。

Add the following piece of code to your page's javascript:

将以下代码添加到页面的javascript中:

$('.ui-autocomplete-input').each(function (idx, elem) {
      var autocomplete = $(elem).data('autocomplete');
      if ('undefined' !== typeof autocomplete) {
            var blur = autocomplete.menu.options.blur;
            autocomplete.menu.options.blur = function (evt, ui) {
                  if (autocomplete.pending === 0) {
                        blur.apply(this,  arguments);
                  }
             };
      }
 });

Credit goes to these folks

归功于这些人