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。在此支持请求页面中,CTools 创建者提到 '#input' => true
是一种解决方法。正如您所看到的,我将其添加到代码中,但效果不佳。
您有什么建议吗?
I am using Ctools Dependency to make a fieldset hideable. This is part of my code:
$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,
);
In snippet above, There are two elements, one select and one fieldset. Both have #process and #dependency parameters and both point to one field for dependent value. Problem is elements like select or textfield can be hidden easily but it does not work for fieldset. In this support request page, CTools creator has mentioned that '#input' => true
is a work around. As you see I added it to code, but it does not work as well.
Do you have any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在阅读了 CTools dependent 的源码后找到了答案。字段集应按如下方式更改:
首先必须为字段集设置 ID。然后它必须包裹在 DIV 标签中。 DIV 的 ID 应该是 feildset 的 ID,后缀为“-wrapper”。
I found my answer after reading the source of CTools dependent. Fieldset should change as this:
First an ID must be set for he fieldset. Then it must be wrapped in a DIV tag. ID of the DIV should be feildset's ID suffixed with '-wrapper'.
现在(2013 年 2 月)用法是:
并且不再需要#process。
now (Feb 2013) usage is:
And #process is no more needed.