jquery.autocomplete 恢复到选项卡上无效的先前建议

发布于 2024-09-15 05:52:05 字数 653 浏览 3 评论 0原文

我正在使用 jQuery Autocomplete 并且用户看到以下行为

  1. :开始输入字符串并显示建议
  2. 用户继续输入,直到不再有任何建议有效(并且下拉菜单消失)
  3. 用户点击选项卡
  4. 自动完成功能用无效的先前建议填充该字段,擦除用户输入的内容

有任何想法吗?

这是 Javascript 代码(来自 Django 模板):

$("#id_name").autocomplete("{% url name_autocomplete %}", {
     formatItem: function(data, i, n, value) {
         values = value.split(",,");
         return values[0];
     },
     formatResult: function(data, value) {
         return value.split(",,")[1];
     },
     highlight: false
});

I'm using jQuery Autocomplete and users are seeing the following behaviour:

  1. User starts typing a string and suggestions are presented
  2. User keeps typing until no suggestions are valid any longer (and drop down goes away)
  3. User hits tab
  4. Autocomplete fills the field with an invalid previous suggestion, wiping away what the user had typed

Any ideas?

This is the Javascript code (from Django template):

$("#id_name").autocomplete("{% url name_autocomplete %}", {
     formatItem: function(data, i, n, value) {
         values = value.split(",,");
         return values[0];
     },
     formatResult: function(data, value) {
         return value.split(",,")[1];
     },
     highlight: false
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡莣 2024-09-22 05:52:11

您确定所描述的行为正是用户正在做的事情吗?我之所以这么问,是因为看起来如果您输入一个自动完成术语,向下滚动到一个选项,输入足够的内容以创建一个无效术语,然后快速按 Tab 键,然后之前突出显示的内容 建议“已提交”。当“步骤 1.5”添加到您的行为时,似乎存在竞争条件:“用户按下向下箭头以突出显示建议。”

如果行为确实正如您所描述的那样,您可以考虑使用 jQuery UI 中的自动完成功能。您链接到的自动完成版本似乎已被弃用。我对 jQuery UI 自动完成的几种不同实现进行了快速测试,它们似乎没有表现出您所描述的行为。

或者,您在 https://github.com/agarzola/jQueryAutocompletePlugin。错误报告和修复似乎没有很好的记录,但也许它们在更新中解决了您的问题(直接或间接)。

Are you certain that the described behavior is exactly what the users are doing? I only ask because it appears that if you type in a autocompletable term, scroll down to an option, type enough to create to create an invalid term, and press tab very quickly then the previously highlighted suggestion is "submitted". There appears to be a race condition when a "step 1.5" is added to your behavior: "User presses the down arrow to highlight a suggestion."

If the behavior is indeed precisely as you have described, you may consider using the autocomplete in jQuery UI. It appears that the version of autocomplete you have linked to is deprecated. I did a quick test on several different implementations of jQuery UI autocomplete and they do not appear to exhibit the behavior you describe.

Alternatively, there appears to be an update to the version you linked at https://github.com/agarzola/jQueryAutocompletePlugin. Bug reports and fixes do not appear to be terribly well documented, but perhaps they fixed your issue in the update (either directly or indirectly.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文