2010-06-16 18 views
5

का उपयोग कर एक फ़ील्ड निर्भर कैसे करें I फ़ील्ड को छिपाने योग्य बनाने के लिए Ctools निर्भरता का उपयोग कर रहा हूं। यह मेरे कोड का हिस्सा है:Drupal: 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'), 
    '#process' => array('ctools_dependent_process'), 
    '#dependency' => array('radio:profile-status' => array('select')), 
    '#input' => true, 
); 

ऊपर स्निपेट में, दो तत्व, एक चयन और एक फ़ील्ड हैं। दोनों में # प्रोसेस और # निर्भरता पैरामीटर हैं और दोनों निर्भर मूल्य के लिए एक फ़ील्ड को इंगित करते हैं। समस्या यह है कि चयन या टेक्स्टफील्ड जैसे तत्व आसानी से छुपाए जा सकते हैं लेकिन यह फ़ील्डसेट के लिए काम नहीं करता है। this समर्थन अनुरोध पृष्ठ में, CTools निर्माता ने उल्लेख किया है कि '#input' => true एक काम है। जैसा कि आप देखते हैं मैंने इसे कोड में जोड़ा है, लेकिन यह भी काम नहीं करता है।

क्या आपके पास कोई सुझाव है?

उत्तर

5

मुझे सीटीयूएल के स्रोत को पढ़ने के बाद मेरा जवाब मिला। फ़ील्डसेट को इस प्रकार बदलना चाहिए:

$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>', 
); 

पहले फ़ील्ड के लिए एक आईडी सेट की जानी चाहिए। फिर इसे एक डीआईवी टैग में लपेटा जाना चाहिए। डीआईवी की आईडी '-वापर' के साथ फीडसेट की आईडी होना चाहिए।

1

अब (2013 फरवरी) उपयोग है:

$form['foo_or_bar'] = array(
    '#title' => 'Foo or Bar', 
    '#type' => 'radios', 
    '#options' => array(
     "foo" => "Foo", 
     "bar" => "Bar" 
    ), 
    '#default_value' => "foo", 
); 

$form['react_on_foo'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Foo fieldset'), 
    '#dependency' => array('radio:foo_or_bar' => array('foo')), 
); 

$form['react_on_foo']['dummy_for_foo_fieldset'] = array(
    '#title' => t('Dummy for FOO fieldset'), 
    '#type' => 'textfield', 
); 


$form['react_on_bar'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Bar fieldset'), 
    '#dependency' => array('radio:foo_or_bar' => array('bar')), 
); 

$form['react_on_bar']['dummy_for_bar_fieldset'] = array(
    '#title' => t('Dummy for BAR fieldset'), 
    '#type' => 'textfield', 
); 

और #process कोई और अधिक की जरूरत है।

संबंधित मुद्दे