Drupal CCK 添加另一个项目回调
在 CCK 多值字段上执行“添加另一个项目”时,我试图让最后一个字段项目成为焦点。
这是我的代码:
$("#node-form table.content-multiple-table tr.draggable input[type='text']").live("keydown", function (e) {
if (e.which == 13) {
$(this).closest("table.content-multiple-table").siblings("div.content-add-more").find("input.form-submit").mousedown();
$(this).closest("tr.draggable").next().find("input[type='text']").trigger("focus");
return false;
}
});
显然这不起作用,因为该字段是在 AHAH 响应上创建的。 :(
有人知道如何挂钩响应以聚焦最后一个字段吗?谢谢。
I'm trying to get the last field item to focus when doing a 'add another item' on a CCK multiple value field.
Here's my code:
$("#node-form table.content-multiple-table tr.draggable input[type='text']").live("keydown", function (e) {
if (e.which == 13) {
$(this).closest("table.content-multiple-table").siblings("div.content-add-more").find("input.form-submit").mousedown();
$(this).closest("tr.draggable").next().find("input[type='text']").trigger("focus");
return false;
}
});
Clearly this doesn't work because the field is created on AHAH response. :(
Anyone know how to hook into the response to focus the last field? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用 Drupal.behaviors Drupal 应该为您管理附加行为。模块应该在修改 DOM(包括 AHAH 请求)后重新运行这些。
在您的情况下,您可能需要添加两种行为,一种是添加到按钮以标记它已被按下,另一种添加到最后一个字段以在设置标志时聚焦(并取消设置标志)。
You should use Drupal.behaviors and Drupal should manage attaching the behaviors for you. Modules should re run these after modifying the DOM (including AHAH requests).
In your case you will probably want to add two behaviors, one to the button to flag that it was pressed and another on the last field to focus if the flag is set (and unset the flag).
查看cck/includes/content.node_form.inc的源代码,更准确地说是content_add_more_js函数中的这部分:
我想说你需要设置hook_form_alter,其中 form_id 是“content_add_more_js”,因为看起来这是在生成新字段之后但在将其添加到页面之前调用的。
不过我还没有尝试过......
Oussama Mubarak // Semiaddict
Looking at the source code of cck/includes/content.node_form.inc, and more precisely this part in the content_add_more_js function:
I'd say you'll need to setup a hook_form_alter where the form_id is 'content_add_more_js', as it seems this is called after generating the new field, but before adding it to the page.
I haven't tried that yet though...
Oussama Mubarak // Semiaddict
最后使用:
http://api.jquery.com/last
Use last:
http://api.jquery.com/last
我遇到了类似的问题(在 D6 中;对于 D7 可能有所不同)。关键是替换
为:
I was having a similar issue (in D6; might be different for D7). The key is replacing
with: