WLineEdit and WSuggestionPopup share EnterPressed and EscapePressed signals
PROBLEM: in the current Wt version, both the popup menu and the corresponding edit receive EnterPressed or EscapePressed signals when the user is selecting a suggestion from the popup. That causes an issue when the edit has its own handlers for these signals.
PROPOSED SOLUTION: the default state of WSuggestionPopup should be "suggestions shown but none highlighted", like in Google's search input. In this state only the edit receives EnterPressed or EscapePressed signals. When the user presses DownArrow or PageDown, one of the suggestions becomes highlighted (let's call it the "highlighted state"). Then, when the user presses Enter, only the popup receives the EnterPressed and the suggestion is placed into the edit. The popup then returns to its default state. If the popup is in the "highlighted state" and the user presses Escape, the popup returns to its default state without placing anything in the edit.
Updated by Koen Deforche almost 11 years ago
- Status changed from New to Resolved
- Assignee set to Koen Deforche
- Target version set to 3.2.0
I'm not sure I follow you all the way. I'm not sure I believe that google's way is necessarily more convenient than the current behaviour of immediately taking the current suggestion on enter-press. In a line-edit (which is the most common use), enter press has no other meaning anyway.
What I did is that I fixed the situation where enterPressed() or escapePressed() would still be emitted if they were already 'used' by the suggestion popup. I can imagine this solves your use-case ?
Updated by Peter K almost 11 years ago
Thank you for making the changes. I have downloaded the latest git version of Wt and ran into 2 issues:
1) A bug somewhere, apparently: When typing into a line edit with a suggestion popup, the browser sometimes shows Wt internal error: SyntaxError: missing ; before statement, code: undefined, description: undefined.
That happens when using the popup with setFilterLength(--1), meaning that the popup requests updated suggestions from the server after every letter typed. In addition, it only happens when typing more quickly than the server can respond (when the requests are "piling up", so to speak).
2) Usage issue. The problem with Enter signal being processed simultaneously by the edit and popup is now solved, thanks. But I still can't quite do what I want though. Let me explain the popup behavior that I am trying to get using an example:
My line edit is used for entering search terms. Let's say user types in "Austr" into the edit. The suggestion popup should then show "Australia" and "Austria", for example (that works fine now). But let's say the user really wants to search for "Austr". Then he should be able just to press Enter and have the event handler for the line edit process "Austr". Right now, however, if he does that, he will instead just select the first suggestion from the popup. Do you see the problem?
So that's why I suggested having a popup state where the suggestions are shown but none are selected, a-la Google. Then this problem of differentiating between line edit entry and popup selection never comes up.
Can that be done?
Updated by Peter K almost 11 years ago
I noticed that problem (1) is gone, thanks.
The second feature - having no selection in the popup by default - is kind of essential for my usage case. That way the user can type any text into a search bar and have it processed by pressing enter, even when the suggestions are shown. I am aiming for the behavior like the Bing search bar, for example.
So something like setDefaultSelected(false) is just what I need.
Also, could it be possible to modify the popup to issue the "filterModel" signal after the user selects a suggestion? Maybe with an additional option, setRefilterOnSelect(true)? Right now the popup just hides after selection, and I'd like it to be updated and shown again.