auto_complete_for:防止自动选择第一项
script.aculo.us 的 auto_complete_for dealio 非常棒,但是有没有办法让我有选择地禁用它总是自动选择列表中的第一项的事实?
问题是,如果我想输入自己的新条目,我不希望自动选择列表中的第一项。原因是因为当我按 TAB 键离开该字段时,它会选择第一个项目并填充文本框。
我通过使列表中的第一项与我输入的内容相同来解决这个问题,但这也不是完美的,因为 auto_complete 列表并不总是随着每次击键而更新,具体取决于我输入的速度。我尝试将列表刷新率设置为最低值(1 毫秒),但没有成功。
我真正想要的是“auto_complete_for”中的一个选项,它根本不选择第一个项目 - 就像 Google Instant 不会自动选择第一个建议的搜索短语一样 - 您必须向下箭头才能选择一个。
也许我可以通过我缺少的 HTML 选项来做到这一点?
The auto_complete_for dealio from script.aculo.us is great an all, but is there a way for me to selectively disable the fact that it always auto-selects the first item in the list?
The problem is that, if I want to type my own entry that is new, and novel, I don't want the first item in the list to be auto-selected. The reason is because when I TAB out of the field, it selects, and fills the text box with that first item.
I got around that, somewhat, by making the first item in the list the same as what I'm typing, but that's not perfect either, because the auto_complete list doesn't always update with every keystroke, depending on how fast I type. I've tried setting the list refresh rate to the lowest value (1 millisecond) but no go.
What I really want is an option in "auto_complete_for" that doesn't select that first item at all - the same way that Google Instant doesn't automatically select the first suggested search phrase - you have to arrow-down to select one.
Maybe I can do this via an HTML option that I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我将添加另一个与 Rails 3 配合良好的替代方案:
http://github.com/crowdint/rails3-jquery-autocomplete
I'll add another alternative that works great with Rails 3:
http://github.com/crowdint/rails3-jquery-autocomplete
我最近为 Rails 2.0.2 的多个字段实现了自动完成。
我使用的插件是:- https://github.com/david-kerins/auto_complete 。不确定它是否支持 Rails 3。
我在实现上述场景时也遇到了问题,并发布了问题( 在 Rails 中实现多个字段的自动完成 ; 在 stackoverflow 上实现 OnClick 类型的功能并格式化 wrt Rails Partial-Views ),我很幸运能够让事情正常工作根据我的要求对我来说。
请参考这些问题,它们可能与您的要求相关。
I recently implemented auto complete for more than a field for Rails 2.0.2.
The plugin I used is:- https://github.com/david-kerins/auto_complete . Not sure if it supports Rails 3.
I have also encountered issues on implementing the above scenario and have posted questions( Implementing auto complete for more than one field in Rails ; Implementing a OnClick kind of functionality and formatting wrt Rails Partial-Views ) on stackoverflow for the same, I have been lucky on getting things working for me based on my requirement.
Kindly refer to these questions, they might have relevance to your requirement.
查看源代码,似乎没有一个选项,但我敢打赌,如果您更改了 controls.js 的第 284 行 到
this.index = -1;
它将执行您想要的操作。否则,可能是时候寻找不同的自动完成小部件了。
Looking at the source, there doesn't appear to be an option for that, but I bet if you changed line 284 of controls.js to
this.index = -1;
it would do what you want.Otherwise, it might be time to look for a different autocomplete widget.
如果您的要求与可用插件相差太远,那么我想没有必要进行修改。最好自己写JS代码。
您可能需要考虑这一点: https://github.com/laktek/jQuery-Smart-自动完成
或这样:https://github.com/reinh/jquery-autocomplete
If your requirements are too far away from the available plugin, then I guess there is no point in tinkering around. Its best to write your own JS code.
You might want to consider this: https://github.com/laktek/jQuery-Smart-Auto-Complete
or this : https://github.com/reinh/jquery-autocomplete