Enter key to trigger submit for dhtmlx combo

Hello,

I’m using a combobox and it’s working fine if the user selects from the popup. But if the user types in an entry and hits “Enter”, it will not trigger.

What I’d like is to add an event capture so that when the user hits Enter, the submit is triggered.

Thank you!

Eric

Hello,

you may try to use onKeyPressed event:

[code]combos[0].attachEvent(“onKeyPressed”,submitForm);

function submitForm(key){
if(key==13)
window.setTimeout(function(){
document.getElementById(“yourform_id”).submit();
},1);
})[/code]

Hello,

Thank you for your reply. I tried your suggestion, but it’s still not quite working for me.
Here is the code I’ve written:

[code]var z = new dhtmlXCombo(“combo_zone4”, “alfa4”, 200);
z.enableFilteringMode(true, “auto_complete.cgi”, true);
z.attachEvent(“onSelectionChange”, onSelectionChangeFunc);
z.attachEvent(“onKeyPressed”,submitForm);

function onSelectionChangeFunc() {
parent.dhxWins.window(‘w2’).hide();
parent.loadTabs(z.getSelectedText());
return true;
}

function submitForm(key){
if(key==13) {
window.setTimeout(function(){
onSelectionChangeFunc();
},1);
}
}[/code]

For some reason, I’m not able get the submitForm to call onSelectionChangeFunc.

Thank you for your help!

Eric

Hello,

doesn’t onKeyPressed event occur when you press Enter ?

Locally the code you’ve provided works correctly.

Hello,

The enter key is indeed triggering. Upon further investigation, it seems that when the user selects a value with the mouse, z.getSelectedText() has the value from the selection. However, when the user uses the enter key, z.getSelectedText() is null.

Can you tell me what I need to do when the enter key is used to make getSelectedText() work properly?

Thank you,

Eric

You may use getComboText() method if getSelectedText() returns null. getComboText() returns text in combo input.

Wonderful! That did the trick!

Thank you for your prompt reply.

Eric

Hello,

I hope you can help again. When I upgraded to 2.6, the combobox stopped working for me. What happens is that when I type any letter that matches, it goes ahead and calls the SelectionChange() function. It used to only happen when the user clicked and entry, or hit the Enter key. Here is a small example:

Thanks in advance!
Eric

Hello,

the onSelectionChange is called when the new option is highlighted (if typing a new letter causes new option highlighting, the event will be called).

If you need to called function on Enter press, you may try to use onChange event instead of onSelectionChange.

I’m not sure what changed to cause my app to break, but your suggestion worked perfectly!

Thank you again, for your always prompt reply.

Eric