Drupal 自动完成提交选择建议
我已按照此站点上的教程进行操作: http:// /thedrupalblog.com/creating-autocomplete-field-using-forms-api-and-menu-callback 并使我的自动完成功能运行良好。
我不确定如何做并且似乎无法在网上找到的是当用户单击建议时提交表单,而不是简单地填写该字段。
提前致谢。
I've followed the tutorial at this site: http://thedrupalblog.com/creating-autocomplete-field-using-forms-api-and-menu-callback and have my autocomplete working great.
What I'm not sure how to do and can't seem to find online is have the form submit when a user clicks a suggestion instead of simply completing that field.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下代码将覆盖“Drupal.jsAC.prototype.select”函数,并且可以在任何 JS 文件中使用它,而无需修改
misc/autocomplete.js
。Following code will override the "Drupal.jsAC.prototype.select" function, and this can be use in any JS file without modifying
misc/autocomplete.js
.这可能不是最好的“drupal”方法,也许有人可以改进它......
在你的“misc/autocomplete.js”文件中找到:
并将其更改为:
然后在你的表单项上添加:
这将导致无论用户选择如何选择(输入按钮或鼠标单击)都要提交表单
编辑:4年后我投票并意识到这需要更新......基本上@Azhar是对的,而不是编辑现有文件,应将此代码添加到在 autocomplete.js 之后加载的新 JS 文件中。
每当您编辑核心时,您都会遇到不得不担心核心安全更新的情况,这会覆盖您的更改并导致您的网站损坏,而您则需要再次修复它。
This may not be the best "drupal" way to do it, maybe someone can improve it...
in your 'misc/autocomplete.js' file find:
and change it to :
then on your form item add:
That will cause the form to submit regardless of how the user chooses to select (enter button or mouse click)
EDIT: 4 years later I got a vote up and realized this needs to be updated...basically @Azhar is right, rather than editing the existing file, this code should be added to a new JS file that loads after autocomplete.js.
As is true any time you edit the core you run into having to worry about core security updates which would override your change and leave your site broken and you scrambling to fix it again.
仅当您单击自动完成建议时,此功能才有效,而通过键盘选择它时则无效。
要捕获键盘和鼠标选择,请重写 hidePopup 方法。
This only works if you click the autocomplete suggestion, not if you select it by keyboard.
To catch both keyboard and mouse selections override the hidePopup method.
或者,如果您想在所有自动完成表单上启用它,而不必使用表单更改,则可以在 JS 文件中使用以下代码片段:
Or, if you want to enable it on all autocomplete forms without having to use a form alter, you can use the following snippet below in your JS file:
自 7.36 /
问题 #365241,通过触发
autocompleteSelect
事件可以更好地支持此问题关于选择。如果您使用 Ajax 框架,您可以捕获此事件以及三种主要类型的字段提交(单击、输入、更新值上的 Tab)的更改事件,例如:
否则,您可以从自定义脚本捕获该事件。它是在编辑元素(更新后)上触发的,并带有所选节点的单元素数组的附加参数。
As of 7.36 /
Issue #365241, this is much better supported by triggering an
autocompleteSelect
event on selection.If you are using the Ajax framework, you can catch this and the change event for the three main types of field commitment (click, enter, tab on updated value), e.g.:
Otherwise, you can catch the event from custom script. It is triggered on the edit element (after update) with an additional parameter of a one-element array of the selected node.
假设您有两个字段,例如标题、描述。我们假设这两个字段中都没有 html 标签。我们设置了一个视图来列出标题和描述。我们还有一个标题作为具有自动完成功能的公开过滤器。
最详细的版本位于 https://www.drupal.org/node/2852380
Suppose you have a two fields such as title, description. We assume both the fields do not have html tags in it. We have set up a view to list the title and description. We also have a title as the exposed filter with auto complete.
Most detailed version is at, https://www.drupal.org/node/2852380