2010-06-16 16 views
5

Utilizzo la dipendenza di Ctools per rendere un field hideable. Questo fa parte del mio codice:Drupal: Come rendere dipendente un fieldset utilizzando 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, 
); 

Nel frammento di sopra, ci sono due elementi, uno di selezione e un fieldset. Entrambi hanno parametri #processo e #dipendenza ed entrambi puntano a un campo per il valore dipendente. Il problema è che elementi come select o textfield possono essere nascosti facilmente ma non funziona per fieldset. Nella pagina di richiesta di supporto this, il creatore di CTools ha menzionato che '#input' => true è un problema. Come vedi, l'ho aggiunto al codice, ma non funziona altrettanto bene.

Avete qualche suggerimento?

risposta

5

Ho trovato la mia risposta dopo aver letto la fonte di CTools dipendente. Fieldset dovrebbe cambiare come questo:

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

Prima deve essere impostato un ID per fieldset. Quindi deve essere racchiuso in un tag DIV. L'ID del DIV dovrebbe essere l'ID di feildset suffisso con "-wrapper".

1

ora (Feb 2013) L'uso è:

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

E #process non più è necessario.

Problemi correlati