加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 04:56:39 所属栏目:百科 来源:网络整理
导读:我正在使用Ctools依赖项使字段集可隐藏.这是我的代码的一部分: $form['profile-status'] = array( '#type' = 'radios','#title' = '','#options' = array( 'new' = t('Create a new profile.'),'select' = t('Use an existing profile.'),),);$form['select
我正在使用Ctools依赖项使字段集可隐藏.这是我的代码的一部分:

$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'),'#input' => true,);

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

你有什么建议吗?

解决方法

在阅读了CTools依赖的来源后,我找到了答案. Fieldset应该改变如下:

$form['profile-properties'] = array(
    '#type' => 'fieldset','#id' => 'my-fs-id','#prefix' => '<div id="my-fs-id-wrapper">','#suffix' => '</div>',);

首先,必须为他的字段集设置ID.然后它必须包装在DIV标签中. DIV的ID应该是feildset的ID,后缀为’-wrapper’.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读