2017-01-02 1 views
1

여러 개의 ajax 가능 양식 요소가있는 drupal 폼을 작성 중입니다.Drupal 8 ajax 콜백 후 ajax 폼 요소 추가

변경 후 ajax 콜백을 수행하는 하나의 선택 목록이 있습니다. 문제는 페이지에 새로운 선택 목록을 추가하고 아약스를 사용할 수있게한다는 것입니다. 이것은 작동하지 않는 것으로 보입니다. 아작스가 실제로 페이지에 추가되어 번들로 사용되므로 replacecommand에서 손실됩니다.

경험이있는 사람이 있습니까? 누구에게도 해결책이 있습니까?

이것은 JS Drupal.attachBehaviors에

/** 
    * {@inheritdoc} 
    */ 
    public function buildForm(array $form, FormStateInterface $form_state) 
    { 
     $form['city'] = [ 
      '#type' => 'select', 
      '#title' => $this->t('Station'), 
      '#description' => $this->t('City'), 
      '#options' => array(
       'Aalst' => $this->t('Aalst'), 
       'Brussel' => $this->t('Brussel'), 
       'Hasselt' => $this->t('Hasselt'), 
       'Leuven' => $this->t('Leuven'), 
      ), 
      '#ajax' => [ 
       'callback' => array($this, 'extendFormAjax'), 
       'event' => 'change', 
       'progress' => array(
        'type' => 'throbber', 
        'message' => t('Choose City'), 
       ), 
      ], 
      '#suffix' => '<div id="extended-form"></div>', 
     ]; 

     $form['submit'] = [ 
      '#type' => 'submit', 
      '#value' => t('Submit'), 
     ]; 

     return $form; 
    } 

    /** 
    * Ajax callback to validate the email field. 
    */ 
    public function extendFormAjax(array &$form, FormStateInterface $form_state) 
    { 
     $parking = [ 
      '#type' => 'select', 
      '#title' => $this->t('Parking'), 
      '#description' => $this->t('Parking'), 
      '#options' => [ 
       'P1' => $this->t('P1'), 
       'P2' => $this->t('P2'), 
      ], 
      '#ajax' => [ 
       'callback' => array($this, 'extendFormAjax'), 
       'event' => 'change', 
       'progress' => array(
        'type' => 'throbber', 
        'message' => t('Choose parking'), 
       ), 
      ], 
     ]; 

     $response = new AjaxResponse(); 
     $response->addCommand(new InsertCommand('#extended-form', $parking)); 

     return $response; 
    } 
+0

이 동일한 문제가 발생하지만 아직 해결책을 찾지 못했습니다. –

답변

1

에 한번 호출 어딘가에 내 코드();