When adding a filter in Views UI, any AJAX trigger on an extra settings form will cause the dialog to go one step back rather than rebuild the current page.

This has been reported for a custom filter handler, but also blocks #2429699: Add Views EntityReference filter to be available for all entity reference fields.

Original report:

Motivation

I'm trying to make views filter plugin, that has an ajax dropdown select, which loads a different set of additional options depending on the selected choice.
If the ajax is triggered first thing after adding the filter criteria, the user is returned back to the "Add filter criteria" list, yet the filter is actually added.

Reproduction

To simplify the problem, I've made a simple module, that adds a filter with an ajax dropdown in the buildExtraOptionsForm function.

  1. Download and install the vaft module included in this issue.
  2. Create a new view.
  3. Add the VAFT Test. filter.
  4. Select a different option in the dropdown.

Instead of proceeding to the next settings form (which is empty in this simply test module), the user is returned to the "Add filter criteria" list.
However the filter is actually added. And if you open the settings up again (by pressing the bolded "Settings" in the filter), the ajax form works as expected.

CommentFileSizeAuthor
vaft.zip2.29 KBbirk

Comments

Birk created an issue. See original summary.

birk’s picture

Version: 8.6.x-dev » 8.7.x-dev

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pancho’s picture

Title: Ajax in a views filter settings form jumps back to the add handler form » Ajax in a Views filter handler extra settings form jumps back
Issue summary: View changes
Priority: Normal » Major

I can confirm this bug, which actually blocks #2429699: Add Views EntityReference filter to be available for all entity reference fields, so raising to major.

Copying over comment #193 by @_Archy_:

[...] I have found that it is caused by the fact that when first adding the filter the AddHandler forms controller path is rendered in the
tag, but the form_id input still has the ConfigHandlerExtra form id inserted into it. This in turn in the FormBuilder causes an if to not throw the FormAjaxException which would normally render the same form.

Now my problems is that I don't quite understand what is the expected behaviour here? Should the form_id be the one from the AddHandler or the path should be changed to be from the ConfigHandlerExtra since we are submitting that form. I will attempt to go with the first solution by changing the ID to the right one and see what happens.

Also note that if aggregation is turned on, AJAX will jump back to the aggregation settings form, so it's literally jumping one step back.

pancho’s picture

Priority: Major » Normal

Found what probably is a workaround in EntityField. You just have to add:
$element['#ajax']['url'] = views_ui_build_form_url($form_state);

This fixed our issue in #2429699: Add Views EntityReference filter to be available for all entity reference fields, too.
However I think that this should be solved more generically, so leaving this issue open, although maybe not as a major one anymore.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative, +Needs issue summary update

This came up as the daily BSI target

The summary mentions a custom module but is this reproducible with straight Drupal?

If no follow up this could be closed in 3 months.