Skip to content

Completer.js: Ensure autosubmit is triggered if no suggestion is selected#355

Open
raviks789 wants to merge 3 commits intomainfrom
fix/completer-autosubmit
Open

Completer.js: Ensure autosubmit is triggered if no suggestion is selected#355
raviks789 wants to merge 3 commits intomainfrom
fix/completer-autosubmit

Conversation

@raviks789
Copy link
Contributor

@raviks789 raviks789 commented Mar 4, 2026

Summary

If Completer has a auto-submit attribute in its dataset, Completer does not trigger autosubmit for manual inputs and the submit event is only triggered when a suggestion is clicked and if a classic 'class' => 'autosubmit' attribute is used, the submit event will be triggered before the suggestion click and this in turn never fills the completer input with the suggestion data.

Fix

Ensures the form submits automatically when:

  • The completer is not part of term input
  • The completer has the auto-submit dataset attribute
  • No suggestion is explicitly selected on manual input

Result

The solution triggers makes the completer to trigger autosubmit on manual input as expected when the focus goes away from the completer, even though no suggestion has been clicked. The classic autosubmit 'class' => 'autosubmit' would still not work with the completer.

Claude Code Assistance

The initial implementation for this change was generated using Claude Code. I reviewed the generated code, verified the logic, and tested it locally and made necessary changes to ensure it behaves correctly and aligns with the project.

@cla-bot cla-bot bot added the cla/signed label Mar 4, 2026
@raviks789 raviks789 requested review from lippserd and nilmerg March 4, 2026 08:25
@raviks789 raviks789 force-pushed the fix/completer-autosubmit branch from 9268541 to 6114283 Compare March 4, 2026 09:05
@raviks789 raviks789 self-assigned this Mar 5, 2026
@raviks789 raviks789 force-pushed the fix/completer-autosubmit branch 2 times, most recently from 2665ab0 to 02f6d4a Compare March 5, 2026 09:48
… not instrumented

Ensure the form submits automatically when:

- The completer is not part of term input or instrumented
- The completer has the autosubmit dataset attribute
- No suggestion is explicitly selected on manual input
@raviks789 raviks789 force-pushed the fix/completer-autosubmit branch from 9597105 to c6f0206 Compare March 6, 2026 09:00
Copy link
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still AI-generated? If not, remove the disclosure.

constructor(input, instrumented = false) {
this.input = input;
this.instrumented = instrumented;
this.hasNotBeenCompleted = false; // Flag to identify if the input has been completed at least once.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below: ! this.hasNotBeenCompleted

Double negation.

Suggestion: this.hasBeenManuallyChanged

Comment on lines 481 to 498
@@ -492,12 +494,20 @@ define(["../notjQuery"], function ($) {
&& ! this.termSuggestions.contains(document.activeElement)
) {
// Hide the suggestions if the user doesn't navigate them
if (input !== completedInput) {
if (completedInput !== null && input !== completedInput) {
// Restore input if a suggestion lost focus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this code path alone please. For one, the comment is not applicable anymore as it doesn't mention your change. Else, the remaining code wasn't intended to handle completedInput = null and you only adjusted one of three cases. Don't try to generalize code like this.

At the very start of the method:

  • Check if ! this.instrumented && this.hasBeenManuallyChanged && this.shouldAutoSubmit()
  • Then immediately reset this.hasBeenManuallyChanged
  • Now trigger the submit, either immediately or with its own timout

@raviks789
Copy link
Contributor Author

raviks789 commented Mar 6, 2026

Is this still AI-generated? If not, remove the disclosure.

No, after these changes, it is not AI generated anymore. But don't we have to mention that it was initially AI generated and then adjusted (made necessary changes ) as I have added in the disclosure?

- rename property hasNotBeenCompleted to hasBeenManuallyChanged
- Separate autosubmit logic from suggestionkiller
@raviks789 raviks789 force-pushed the fix/completer-autosubmit branch from 678f47b to ee71399 Compare March 6, 2026 12:09
@raviks789 raviks789 requested a review from nilmerg March 6, 2026 12:10
Copy link
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still an issue with duplicated auto submissions:

  • Type in the input and wait for suggestions
  • Choose a suggestion with the mouse
  • Notice an aborted request in the network log

The request that is aborted should have never occurred because of the interaction with the suggestions.

This gets worse if you try to navigate the suggestion list with the keyboard.

No, after these changes, it is not AI generated anymore. But don't we have to mention that it was initially AI generated and then adjusted (made necessary changes ) as I have added in the disclosure?

Once any trace of AI generated code is gone, there's no reason for the disclosure anymore. This is about for what AI was being used, nothing else. I'll write up my reasoning some time soon probably, so it's clear to everyone why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants