PDA

View Full Version : Combobox specialkey enter - imitate Google autocomplete



pdm
21 Nov 2013, 3:26 AM
I'm trying to imitate Google search suggestions behaviour using combobox autocomplete.

I have a listener on select event working fine, but then I want to handle the enter key and submit the current value when no autocomplete suggested is highlighted.



onComboboxSelect: function(combo, records, eOpts){
// get the autocomplete suggestion when clicking or using down arrow and hitting enter
console.log(records[0]);
}

onComboboxSpecialkey: function(field, e, eOpts){
if (e.getKey() == e.ENTER) {
// get the rawValue when nothing is selected
console.log(field.rawValue);
}
}

That's ok but how do I stop the specialkey enter key event handler interfering with hitting enter when selecting a record from autocomplete suggestions? Both events get fired.

scottmartin
26 Nov 2013, 10:01 AM
Perhaps you could check to see of the picker is expanded?

pdm
27 Nov 2013, 12:52 AM
the combobox can be expanded but with nothing selected. However, I can't seem to access what's selected from the 'field' object passed to the specialkey handler.

scottmartin
27 Nov 2013, 6:36 AM
My thought was for you to check to see if the picker was expected on your special key to determine if any action should be taken, not to get any actual value.

pdm
27 Nov 2013, 7:15 AM
Yes, I understood you. I already tried that. The picker gets expanded when there are suggestions available. So what happens when I don't want any of those suggestions, I want to just hit enter? I need to differentiate between hitting enter to select a focused suggestion and hitting enter on the input in the box with suggestions showing but none selected.