2013-08-23 4 views
0

내 페이지에 요소가 표시되는 데 문제가 있습니다. 역할의 선택에 따라 라디오는 선택 요소를 숨겨야합니다.요소 표시/숨기기 ajax Drupal

$form['field_test_field']['#access'] = 0; 

을하지만 상태 변경 내가 1을 결합하여 다시 가져올 수 아닌가요 그래서 내 조각 이잖아 : 그래서 다음과 같이 hidin`에게 요소를 메신저

function seven_form_user_register_form_alter(&$form, &$form_state, $form_id) { 
    $form['account']['roles']['#ajax'] = array(
     'callback' => 'seven_dynamic_form_ajax_callback', 
     'wrapper' => 'replace_droplist', 
     'event' => 'change', 
    ); 

    $form['field_test_field']['#prefix'] = '<div id="replace_droplist">'; 
    $form['field_test_field']['#suffix'] = '</div>'; 
    $form['account']['roles']['#type'] = 'radios'; 

    $checkedRole = isset($form_state['values']['roles']) 
     ? $form_state['values']['roles'] : 0; 

    if ($checkedRole == 0) { 
     $form['field_test_field']['#access'] = 1; 
    } elseif ($checkedRole == 4) { 
     $form['field_test_field']['#access'] = 0; 
    } elseif ($checkedRole == 3) { 
     $form['field_test_field']['#access'] = 1; 
    } 
}; 

function seven_dynamic_form_ajax_callback($form, $form_state) { 
    return $form['field_test_field']; 
} 

감사합니다. 나를 숨기고 체크 박스의 클릭에 따라 특정 형태의 요소를 표시하는

+0

ive #access 속성을 #disabled로 변경 했으므로 라디오 버튼을 사용하여 구성 요소를 켜고 끌 수 있지만 다음과 같은 이유 때문에 #access가 differrent 동작을 사용하는 이유가 없습니다. – user2709715

답변

0
<code> 
$form['enter_amt'] = array(
    '#type' => 'checkbox', 
    '#title' => t('Enter Billable Amount'), 
); 
    $form['billable_ctc'] = array(
    '#type' => 'textfield', 
    '#title' => t('Billable CTC'), 
    '#maxlength' => '15', 
    '#field_prefix' => t('Rs.'), 
    '#states' => array('invisible' => array(':input[name="enter_amt"]' =>   array('checked' => TRUE),),), 
); 
    $form['billing_rate'] = array(
    '#type' => 'textfield', 
    '#title' => t('Billing rate'), 
    '#maxlength' => '7', 
    '#field_suffix' => '%', 
    '#size' => 3, 
    '#attributes' => array('class' => array('auto-width')), 
    '#states' => array('invisible' => array(':input[name="enter_amt"]' => array('checked' => TRUE),),), 
); 
</code> 

이 코드는했다.