How to close modal after form submit? I am building an entity reference widget, which displays the reference link, next to the input field, to the target entity's edit form. 
I make it to open in a modal, with the following attributes on the link:

 'class' =&gt; ['use-ajax'],
          'data-dialog-type' =&gt; 'modal',
          'data-dialog-options' =&gt; json_encode([
            'height' =&gt; 700,
            'width' =&gt; 900,
          ]),


That works perfectly. However when I click submit on the modal form, I got redirected to the referenced entity view page, instead of the modal being closed and stay on the original form, where this widget is being used.

Is there any special attributes (like "data-dialog-type") which tells to the modal form's submit button to close the modal instead of redirecting to the original view?

UPDATE

Adding this to the URL actually pretty much solves the problem:

    'query' =&gt; [
      'destination' =&gt; $this-&gt;requestStack-&gt;getCurrentRequest()-&gt;getRequestUri(),
    ],


This redirects the to the original page, with the potential values being updated (referenced item title), which is actually a pretty good thing!

That being said, I am still interested in the "ajax submit" version!
You need to implement and use your own EntityEditForm - is this the case ?
Then skip to the last code block :D

Otherwise you'll need to accomplish this first.
See this answer (Overriding an entity add/edit form through alterroute) for an approach to 'inject' a custom form. Here the crucial code to it (adapted to NodeForm):

modules/custom/form_overwrite/form_overwrite.services.yml

services:
    route_subscriber:
        class: Drupal\form_overwrite\Routing\RouteSubscriber
        tags: 
 - {name: event_subscriber }


modules/custom/form_overwrite/src/Routing/RouteSubscriber.php

 &lt;?php

/**
 * @file
 * Contains \Drupal\form_overwrite\Routing\RouteSubscriber.
 */

namespace Drupal\form_overwrite\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
     if ($route = $collection-&gt;get('entity.node.edit_form')) {
  $route-&gt;setDefault('_entity_form', '\Drupal\form_overwrite\Form\NewEditForm');
     }

   }
}


modules/custom/form_overwrite/src/Form/NewEditForm.php

&lt;?php

namespace Drupal\form_overwrite\Form;

use Drupal\node\NodeForm;


/**
 * Form handler for the node edit forms.
 */
class NewEditForm extends NodeForm {}


There you make sure the #ajax is set, like:

&lt;?php

public function form(array $form, FormStateInterface $form_state) {
   ...
   $form['actions']['DESIRED_EXISTING_ACTION'] = array(
      ...
      '#type' =&gt; 'submit',
      '#ajax' =&gt; array(
        'callback' =&gt; '::ajaxSubmit',
        'event' =&gt; 'click',
      ),
      ...
    );
   ...
}


and overwrite the ajaxSubmit function, adding the CloseModalDialogCommand, like:

public function ajaxSubmit(array &amp;$form, FormStateInterface $form_state) {
    $response = new AjaxResponse();

    if ($form_state-&gt;getErrors()) {
      ...
    }
    else {
      ...
      $response-&gt;addCommand(new \Drupal\Core\Ajax\CloseModalDialogCommand\CloseModalDialogCommand());
    }

    return $response;
  }