entity - Node edit form ajax-submit with field collection items doesn't work second time -


i'm working on d8 project , i'm doing load node edit forms in blocks , place them in panel pages. submit forms using ajax.

my code works fine of forms except consist of field collection items.

in 1 content type have 2 field collection items. first field (x_field_collection), consist of 4 fields (status, date1, date2 , milestone taxonomy term reference).

in form_alter, specific form_id i'm doing:

    $form['#attributes']['class'][] = $ajax_id;     $form['actions']['submit']['#submit'][] = 'drupal\my_module\plugin\form\formalter::ajaxformentityformsubmit';     $form['actions']['submit']['#ajax'] = array(       'callback' => 'drupal\my_module\plugin\form\formalter::ajaxformentitycallback',       'wrapper' => $ajax_id,       'effect' => 'fade',     );     $form['ajax_form_entity'] = [       '#type' => 'hidden',       '#value' => [         'reload' => '.reload',         'form_selector' => '.' . $ajax_id,         'show_message' => true,       ]     ]; 

my form submit function:

 public static function ajaxformentityformsubmit($form, &$form_state) {     $entity = $form_state->getbuildinfo()['callback_object']->getentity();      // clear user input.     $input = $form_state->getuserinput();     // should not clear system items user input.     $clean_keys = $form_state->getcleanvaluekeys();     $clean_keys[] = 'ajax_page_state';     foreach ($input $key => $item) {       if (!in_array($key, $clean_keys) && substr($key, 0, 1) !== '_') {         unset($input[$key]);       }     }      // store new entity display in ajax callback.     $input['entity'] = $entity;     $form_state->setuserinput($input);      // rebuild form state values.     $form_state->setrebuild();     $form_state->setstorage([]);  } 

and callback:

  public static function ajaxformentitycallback(&$form, \drupal\core\form\formstateinterface $form_state) {     // if errors, returns form errors , messages.     if ($form_state->hasanyerrors()) {       return $form;     }     // else show result.     else {       $userinputs = $form_state->getuserinput();       $entity = $userinputs['entity'];       $entity_type = $entity->getentitytypeid();       $configurations = $form_state->getvalue('ajax_form_entity');        $response = new ajaxresponse();        // messages if not shown.       $status_messages = array('#type' => 'status_messages');       $message = \drupal::service('renderer')->renderroot($status_messages);        // reload form.         $response->addcommand(new replacecommand($configurations['form_selector'], $form));        return $response;     }   } 

i'm not getting errors or error logs. form not submitted second time. think has fact form contains field collection items entities don't know how double check or better how solve this.

---- update ----

i found problem have no idea how fix it. in node have 2 field collection items. when submit form , reload form first field collection item , mandatory fields of second field collection item empty. idea how fix this?

thanks in advance help!


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -