Handling data from form in modal dialog I'm building a tool that contains a few clickable regions. Each region has a link with class="use-ajax" data-dialog-type="modal" pointing at a custom form route. 

Everything is working great and I'm able to get the data from the form and store it. I, however, need the user's selection in this modal form to be reflected in the region they initially clicked.

I'm at a loss aside from storing their selections in localStorage or something and populating that region when they close each modal. That seems a little hacky though. Is there a cleaner way of accomplishing this that I'm missing? 

&lt;div class="region"&gt;
    &lt;a class="use-ajax" data-dialog-options="{&amp;quot;width&amp;quot;:550, &amp;quot;dialogClass&amp;quot;: &amp;quot;my-region-class&amp;quot; }" data-dialog-type="modal" href="/route/to/custom/form"&gt;
      &lt;div class="content"&gt;
      Click to select
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;/div&gt;
You can pass down your region's ID as parameters to your route. For example:

&lt;a class="use-ajax" data-dialog-options="{&amp;quot;width&amp;quot;:550, &amp;quot;dialogClass&amp;quot;: &amp;quot;my-region-class&amp;quot; }" data-dialog-type="modal" href="/route/to/custom/form/this-region"&gt;...&lt;/a&gt;


As explained here you can add arguments from the route to your form.

On the buildForm method you can have something like this

public function buildForm(array $form, FormStateInterface $form_state, $region = NULL) {
  // Your code...
  $form += [
    'button' =&gt; [
      '#type' =&gt; 'button',
      '#value' =&gt; $this-&gt;t('Submit this form),
      '#name' =&gt; 'ajax_trigger',
      '#ajax' =&gt; [
        'callback' =&gt; '::updateRegionAjaxCallback',
        'wrapper' =&gt; $region, // Assuming $region is the argument passed down.
        'method' =&gt; 'replace',
        'effect' =&gt; 'fade',
        'event' =&gt; 'click',
      ],
    ],
  ];
}


Later your callback method could look like.

public static function updateRegionAjaxCallback(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $response-&gt;addCommand(new AppendCommand(NULL, [
    // Your render array with the data to be displayed.
    '#cache' =&gt; [
      'max-age' =&gt; Cache::PERMANENT,
      'contexts' =&gt; ['url'],
    ],
  ]));

  return $response;
}


This should work but keep in mind that will be best capture the form submit and triggering a custom AJAX event.