Note that there are some explanatory texts on larger screens.

plurals
  1. POZK Combobox onSelect events
    primarykey
    data
    text
    <p>I'm writing a composite component, based on <code>Combobox</code>, to do tokenized autocomplete. The basic idea is that the <code>Combobox</code> queries the model for items that match the current text, and when the user selects something from the options presented it's added to another list for tokenized presentation. Overall it looks like the inputs you may have seen in Facebook, Apple Mail and various other places.</p> <p>My current problem seems to stem from not really being able to determine when the user has selected something from the list, as opposed to merely having navigated up/down the list using cursor keys. <code>Combobox#onSelect</code> seems to be triggered when navigating the list of options in the drop down, and what I really need is a way to grab the selection when the user has done the "I want this one" action, typically pressing Enter with a selection in the drop down, or manually selecting an entry in the drop down with the mouse.</p> <p>The best I have so far come up with is to monitor <code>Combobox#onOpen</code>, check if <code>OpenEvent#isOpen</code> is false, and then inspect the model manually for selection.</p> <p>Is there a better way to become aware of, or detect, the "I want this one" scenario and differentiate it from the <code>onSelect</code> events triggered during "I want the third option down so I'll DOWN, DOWN, DOWN + ENTER"?</p> <p>The code below is basically what I'm looking at now</p> <pre><code>public void onOpen$input(OpenEvent oe) { logger.info("OpenEvent.isOpen: {}", oe.isOpen()); if (oe.isOpen() == false) { ListModel model = this.input.getModel(); logger.info("model: {}", model); if (model instanceof Selectable) { logger.info("model is Selectable"); Set&lt;?&gt; selection = ((Selectable) model).getSelection(); logger.info("selection: {}", selection); for (Object selected : selection) { logger.info("selected: {}", selected); if (selected instanceof Comboitem) { logger.info("selected is Comboitem"); selected = ((Comboitem) selected).getValue(); logger.info("selected: {}", selected); } addToken(selected); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload