Problem/Motivation

The AI Search Block submit button currently binds a mousedown handler that calls preventDefault(), stops propagation, and manually triggers form submission.

That prevents the normal browser click event from firing on the submit button. As a result, click-based analytics and delegated listeners, such as Matomo tracking, cannot observe AI search submissions triggered with the mouse.

The current behavior still submits the form, but it suppresses the native click event chain entirely.

This affects the current upstream code in both the 1.0.x and 2.0.x branches.

Steps to reproduce

  1. Install and enable AI powered Search Block.
  2. Place an AI search block on a page.
  3. Add a click listener or analytics listener to the submit button, for example Matomo delegated click tracking.
  4. Open the page in the browser.
  5. Enter a valid search query.
  6. Submit the form by clicking the submit button with the mouse.

Actual result: the AI search request is submitted, but the native click event does not fire, so the tracking listener is never triggered.

Expected result: the AI search request is submitted and the normal bubbling click event is still available for analytics/tracking.

Proposed resolution

Keep the mousedown guard that blocks unwanted mousedown-based AJAX handlers, but stop canceling the native button behavior.

The proposed change is to:

  • keep stopImmediatePropagation() on mousedown,
  • keep stopPropagation() on mousedown,
  • remove preventDefault(),
  • remove the manual $form.trigger('submit'),
  • remove return false.

This allows the browser to continue with the normal click/submit flow, while the existing form submit handler in ai_search_block.js still controls validation, loading state, streaming, and result rendering.

Remaining tasks

  • Review the attached patch.
  • Test mouse click submission.
  • Test keyboard submission when submit-on-enter is enabled.
  • Confirm no duplicate or unintended Drupal AJAX submission is triggered.

User interface changes

None.

API changes

None.

Data model changes

None.

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

jorgik created an issue. See original summary.

jorgik’s picture

Status: Active » Needs review
arianraeesi’s picture

nikro’s picture

Assigned: Unassigned » nikro
nikro’s picture

Assigned: nikro » wouters_f
Status: Needs review » Reviewed & tested by the community

Tested - all works, MR is good, solves the issue!

Good job!

nikro’s picture

Status: Reviewed & tested by the community » Fixed

*actually* - merging :)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • jorgik committed 7cb21cc1 on 1.0.x
    Issue #3584999: Restore native submit click event