Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 300526

Ajax callback inside views plugin doesn't work.

$
0
0

Problem/Motivation

When you make a new views plugin wiith ajax form inside, the ajax callback of form not working on the first reload.
If you open the settings of plugin in a second time everything is ok.
I tested it on row, style and filter.

Steps to reproduce

For example you can try with the module better exposed filter
or
Add new views plugin (row, style, filter)
Implement buildOptionsForm() method with an ajax callback


  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($original_form, $form_state);
    $form['test']=[
      "#type" => "select",
      '#default_value' => "test",
      "#title" => t("Component"),
      "#options" => ['test'=>'test','test2'],
      '#ajax' => [
        'callback' => __CLASS__. '::changeSelectorFormChangeAjax',
        'wrapper' => 'test',
        'effect' => 'fade',
        '#suffix' => '<div id="test"></div>'
      ],
      '#executes_submit_callback' => FALSE,
      '#required' => TRUE,
    ];
  }

  /**
   * Ajax callback for component selector change.
   */
  public static function changeSelectorFormChangeAjax(
    array $form,
    FormStateInterface $form_state,
  ) {
    return ['#markup'=>'hello'];
  }

1 Add your plugin
2 Choose your plugin inside views ui
3 After the first callback ajax the form options of plugin is loaded
4 Try the callback ajax of the form options => the ajax callback of the previous submit is trigger

Proposed resolution

The problem seems to be that the wrong form is set when the trigerring element is set.
For example a row plugin, after the click on ajax option form, the $formState->get('section') give 'row' and instead of 'row_option' (/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php) and also rebuild the previous form.

I don't know where this 'section' of formstate is set but it may be the problem

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 300526

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>