Drupal:将 onchange 代码添加到 form_alter 中的 option_widgets 中?

发布于 2024-08-19 10:34:38 字数 1417 浏览 8 评论 0原文

有谁知道如何将以下内容添加到 form_alter 中? 目前我有两个整数 cck 字段,它们是使用 php value 命令从 sql 填充的。

一个字段用于品牌,另一个字段用于模型。品牌和型号都是它们自己的节点类型。模型有一个节点参考要制作。

我想要在“Make”下拉菜单(CCK:INTEGER:SELECT)上执行的操作是更改,修改模型字段的内容。我已经制作了自己的定制表单,但它太实用了,并且想要使用基本的 drupal 节点编辑表单。

理想情况下,我希望能够将其传递到混合中。 '#attributes'=>; array ('onchange'=> 'populatemodels(this,\'edit-field-model\')')

有谁知道在代码中执行此操作的一种方法吗?

在我的 form_alter 中添加属性不会在代码中产生任何 onchanges:

#field_make (Array, 14 elements)

    *
      #type (String, 20 characters ) optionwidgets_select
    *
      #default_value (Array, 1 element)
          o
            0 (Array, 1 element)
                +
                  value (String, 1 characters ) 8
    *
      #required (String, 1 characters ) 1
    *
      #columns (Array, 1 element)
          o
            0 (String, 5 characters ) value
    *
      #title (String, 4 characters ) Make
    *
      #description (String, 0 characters )
    *
      #delta (Integer) 0
    *
      #field_name (String, 10 characters ) field_make
    *
      #type_name (String, 3 characters ) car
    *
      #tree (Boolean) TRUE
    *
      #weight (String, 2 characters ) -1
    *
      #access (Boolean) TRUE
    *
      #count (Integer) 9
    *
      #attributes (Array, 1 element)
          o
            onchange (String, 39 characters ) populatemodels(this,'edit-field-model')

谢谢 - Matt

Do anyone know how I can add the following to form_alter?
Currently I've got two integer cck fields which are populated from sql using the php values command.

One field is for make, and the other is for model. Both makes and models are their own node types. Model has a node reference to make.

What I want to do on the Make drop down (CCK: INTEGER : SELECT), is on change, modify the contents of the model field. I've made my own bespoke form up, but it's too wieldy and want to use the basic drupal node edit forms.

Ideally I want to be able to pass this into the mix.
'#attributes' => array ('onchange'=> 'populatemodels(this,\'edit-field-model\')')

Does any one know of a way of doing this in the code?

In my form_alter adding the attribute doesn't produce any onchanges in the code:

#field_make (Array, 14 elements)

    *
      #type (String, 20 characters ) optionwidgets_select
    *
      #default_value (Array, 1 element)
          o
            0 (Array, 1 element)
                +
                  value (String, 1 characters ) 8
    *
      #required (String, 1 characters ) 1
    *
      #columns (Array, 1 element)
          o
            0 (String, 5 characters ) value
    *
      #title (String, 4 characters ) Make
    *
      #description (String, 0 characters )
    *
      #delta (Integer) 0
    *
      #field_name (String, 10 characters ) field_make
    *
      #type_name (String, 3 characters ) car
    *
      #tree (Boolean) TRUE
    *
      #weight (String, 2 characters ) -1
    *
      #access (Boolean) TRUE
    *
      #count (Integer) 9
    *
      #attributes (Array, 1 element)
          o
            onchange (String, 39 characters ) populatemodels(this,'edit-field-model')

Thanks - Matt

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

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

发布评论

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

评论(1

巨坚强 2024-08-26 10:34:38

我想我已经有了突破。

cck/options_widgets.module
optionwidgets_select_process($element, $edit, &$form_state, $form) {

另外,在我的 form_alter 代码中,我添加了

drupal_add_js('sites/all/modules/adaptive/adaptive.js');

其中包含 populatemodels 脚本,

以便将属性传递到下一步

$element[$field_key] = array(
    '#type' => 'select',
    '#title' => $element['#title'],
    '#description' => $element['#description'],
    '#required' => isset($element['#required']) ? $element['#required'] : $field['required'],
    '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'],
    '#options' => $options,
    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
    >>> '#attributes' => isset($element['#attributes']) ? $element['#attributes'] : NULL, <<
  );

我已修改此代码, isset($element['#attributes']) ? $element['#attributes'] :NULL,onchange 现在出现在渲染的代码中。

I think I've had a break through.

cck/options_widgets.module
optionwidgets_select_process($element, $edit, &$form_state, $form) {

Additionally in my form_alter code, I added

drupal_add_js('sites/all/modules/adaptive/adaptive.js');

Which holds the populatemodels script

I've modded this code so that it passes attributes onto the next step

$element[$field_key] = array(
    '#type' => 'select',
    '#title' => $element['#title'],
    '#description' => $element['#description'],
    '#required' => isset($element['#required']) ? $element['#required'] : $field['required'],
    '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'],
    '#options' => $options,
    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
    >>> '#attributes' => isset($element['#attributes']) ? $element['#attributes'] : NULL, <<
  );

By adding '#attributes' => isset($element['#attributes']) ? $element['#attributes'] : NULL, the onchange now appears in the rendered code.

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