far*_*zan 5 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,
);
Run Code Online (Sandbox Code Playgroud)
在上面的代码片段中,有两个元素,一个是select,一个是fieldset.两者都有#process和#dependency参数,并且都指向依赖值的一个字段.问题是像select或textfield这样的元素可以很容易地隐藏,但它不适用于fieldset.在这个支持请求页面中,CTools创建者提到这'#input' => true
是一个解决方法.如您所见,我将其添加到代码中,但它不起作用.
你有什么建议吗?
在阅读了CTools依赖的来源后,我找到了答案.Fieldset应该改变如下:
$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>',
);
Run Code Online (Sandbox Code Playgroud)
首先,必须为他的字段集设置ID.然后它必须包装在DIV标签中.DIV的ID应该是feildset的ID,后缀为'-wrapper'.
归档时间: |
|
查看次数: |
2558 次 |
最近记录: |