Problem/Motivation

Since Drupal core added removeExposedFiltersQueryParameters() to ajax_view.js (fix for #3121172), entity browser views with exposed filters throw a JavaScript error:

TypeError: parameter 1 is not of type 'HTMLFormElement'
    at Drupal.views.ajaxView.removeExposedFiltersQueryParameters

Core's removeExposedFiltersQueryParameters() calls new FormData($exposedForm.get(0)), which requires an HTMLFormElement. In entity browser, the view's exposed form is rendered as a <div> (not <form>) because it's nested inside the entity browser <form method="post">. Entity browser's entity_browser.view.js sets views_instance.$exposed_form to this <div>, then core's method fails.

Steps to reproduce

  1. Create an entity browser with a view widget that has exposed filters.
  2. Open the entity browser modal.
  3. Use any exposed filter and press Search.
  4. JavaScript error is thrown, AJAX request fails.

Proposed resolution

In entity_browser.view.js, override removeExposedFiltersQueryParameters on the views instance before calling attachExposedFormAjax (since it calls the method internally). When $exposedForm is not an HTMLFormElement, collect input names via jQuery's :input[name] selector instead of new FormData(). When it is a real <form>, delegate to core's original method.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

saidatom created an issue. See original summary.

saidatom’s picture

Issue summary: View changes
saidatom’s picture

Version: 7.x-1.x-dev » 8.x-2.x-dev

saidatom’s picture

Status: Active » Needs review
huzooka’s picture

Title: TypeError in removeExposedFiltersQueryParameters: exposed form in a div, not a form element » [PP-1] TypeError in removeExposedFiltersQueryParameters: exposed form in a div, not a form element
Category: Bug report » Task
Status: Needs review » Postponed

Postponing on #3121172: Exposed filters get values from url when ajax is on because it is the ticket which causes this type error and the code there is still the subject of change.

Changed ticket category to "Task" because if there is a bug, then it is caused by a non-BC change in core.