Drupal CCK 添加另一个项目回调

发布于 2024-08-18 21:58:16 字数 531 浏览 6 评论 0原文

在 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 技术交流群。

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

发布评论

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

评论(4

墨小沫ゞ 2024-08-25 21:58:16

您应该使用 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).

坏尐絯℡ 2024-08-25 21:58:16

查看cck/includes/content.node_form.inc的源代码,更准确地说是content_add_more_js函数中的这部分:

  // Build our new form element for the whole field, asking for one more element.
  $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1);
  $form_element = content_field_form($form, $form_state, $field);
  // Let other modules alter it.
  drupal_alter('form', $form_element, array(), '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:

  // Build our new form element for the whole field, asking for one more element.
  $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1);
  $form_element = content_field_form($form, $form_state, $field);
  // Let other modules alter it.
  drupal_alter('form', $form_element, array(), 'content_add_more_js');

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

半城柳色半声笛 2024-08-25 21:58:16

我遇到了类似的问题(在 D6 中;对于 D7 可能有所不同)。关键是替换

jQuery(document).ready(function(){
//your stuff happens
});

为:

Drupal.behaviors.myModuleBehavior = function (context) {
//your stuff happens
};

I was having a similar issue (in D6; might be different for D7). The key is replacing

jQuery(document).ready(function(){
//your stuff happens
});

with:

Drupal.behaviors.myModuleBehavior = function (context) {
//your stuff happens
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文