0

i'm currently working on a custom field/widget.

For a better ux i want to display some nested elements in a modal dialog. The elements are generated during form submission (multistep widget) i added a custom ajax callback like this: (For better understanding i reduced the code)

public static function myAjaxCallback(array $form, FormStateInterface $form_state) {
    $response = new AjaxResponse();

    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $response->setAttachments($form['#attached']);

      $button = $form_state->getTriggeringElement();
      $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3));

      $response->addCommand(
        new OpenModalDialogCommand('Only a few sub elements', $element, [])
      );

      return $response;
} 

The problem in this function is the elements are, obviously, rendered without a form around and so they can't get submitted.

Which would be the correct way to display only some nested elements in an ajax dialog?

Best regards Michael

2
  • You could hide the unwanted form elements, see here drupal.stackexchange.com/questions/41748/… (this is still the same in D8)
    – rémy
    Commented Jul 18, 2016 at 15:12
  • The problem is they are nested in multiple dragndrop containers. In this case this won't work. Thanks anyway! Commented Jul 18, 2016 at 15:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.