- Issue created by @musa.thomas
- π³πΏNew Zealand quietone
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.
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.
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
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
Active
10.4 β¨
Last updated
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.