Hi people!
I recently have to implement in my app a behavior to make the ENTER key focus the next input on the form instead of sumbitting (default action).
I found a solution, where I included the following code in my pages:has páginas:
$(document).ready(function() {
textboxes = $("input, select, textarea");
if ($.browser.mozilla) {
$(textboxes).keypress (checkForEnter);
} else {
$(textboxes).keydown (checkForEnter);
}
function checkForEnter (event) {
if (event.keyCode == 13) {
currentBoxNumber = textboxes.index(this);
if (textboxes[currentBoxNumber + 1] != null) {
nextBox = textboxes[currentBoxNumber + 1]
nextBox.focus();
event.preventDefault();
return false;
}
}
}
});
With the default dropdownlist It works very well (as with the other input fields). When you press ENTER, the focus jumps to the next input field.
The problem is with the XSelect2 widget (http://www.eha.ee/labs/yiiplay/index.php/en/site/extension?view=select2). When you touch ENTER, the widget opens to select an option. I switched this off by using the ‘options’=>array(‘openOnEnter’=> false,) clause, but now the ENTER key doesn’t give any behavior in that field. It doesn’t nothing.
Would It have a way to make this widget work like the others?
Thanks!