Completer.js: Ensure autosubmit is triggered if no suggestion is selected#355
Completer.js: Ensure autosubmit is triggered if no suggestion is selected#355
Conversation
9268541 to
6114283
Compare
2665ab0 to
02f6d4a
Compare
… 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
9597105 to
c6f0206
Compare
nilmerg
left a comment
There was a problem hiding this comment.
Is this still AI-generated? If not, remove the disclosure.
asset/js/widget/Completer.js
Outdated
| 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. |
There was a problem hiding this comment.
Below: ! this.hasNotBeenCompleted
Double negation.
Suggestion: this.hasBeenManuallyChanged
asset/js/widget/Completer.js
Outdated
| @@ -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 | |||
There was a problem hiding this comment.
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
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
678f47b to
ee71399
Compare
nilmerg
left a comment
There was a problem hiding this comment.
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.
Summary
If Completer has a
auto-submitattribute 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:
auto-submitdataset attributeResult
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.