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
- Install and enable AI powered Search Block.
- Place an AI search block on a page.
- Add a click listener or analytics listener to the submit button, for example Matomo delegated click tracking.
- Open the page in the browser.
- Enter a valid search query.
- 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()onmousedown, - keep
stopPropagation()onmousedown, - 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.
Issue fork ai_search_block-3584999
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
Comment #3
jorgik commentedComment #4
arianraeesi commentedComment #5
nikro commentedComment #6
nikro commentedTested - all works, MR is good, solves the issue!
Good job!
Comment #7
nikro commented*actually* - merging :)