我正在使用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’.