Drupal:如何使用 CTools 使字段集依赖

标签 drupal drupal-ctools

我正在使用 Ctools Dependency 使字段集可隐藏。这是我的代码的一部分:

$form['profile-status'] = array(
    '#type' => 'radios',
    '#title' => '',
    '#options' => array(
        'new' => t('Create a new profile.'),
        'select' => t('Use an existing profile.'),
    ),
);

$form['select'] = array(
    '#type' => 'select',
    '#title' => t('Select a profile'),
    '#options' => $options,
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:profile-status' => array('select')),
);

$form['profile-properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('View the profile'),
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:profile-status' => array('select')),
    '#input' => true,
);

在上面的片段中,有两个元素,一个选择和一个字段集。两者都有#process 和#dependency 参数,并且都指向一个字段以获取相关值。问题是像 select 或 textfield 这样的元素可以很容易地隐藏,但它不适用于 fieldset。在 this支持请求页面,CTools 创建者提到 '#input' => true是一种解决方法。如您所见,我将其添加到代码中,但效果不佳。

你有什么建议吗?

最佳答案

我在阅读了依赖 CTools 的源代码后找到了答案。字段集应更改为:

$form['profile-properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('View the profile'),
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:profile-status' => array('select')),
    '#input' => true,

    '#id' => 'my-fs-id',
    '#prefix' => '<div id="my-fs-id-wrapper">',
    '#suffix' => '</div>',
);

首先必须为字段集设置一个 ID。然后它必须被包裹在一个 DIV 标签中。 DIV 的 ID 应该是带有“-wrapper”后缀的 feildset 的 ID。

关于Drupal:如何使用 CTools 使字段集依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3051697/

相关文章:

javascript - Drupal Ctools - 在模态事件上触发 jquery

drupal - 为特定内容类型自定义创建内容表单

Java 与 Drupal-6/PHP

jquery - $(window).load 的 Drupal 7 jQuery 语法是什么?

drupal - 如果我在 Drupal 8 中有两种内容类型并且它们之间存在关系,为什么我要在这两种内容类型中都放置一个引用字段?

forms - 使用 drupal_http_request 上传 Drupal 表单 api 文件

drupal ctools - 如何在模态中显示 View

css - 德鲁帕尔: "Unable to create CTools CSS cache directory. Check the permissions on your files directory."?