Skip to content

Instantly share code, notes, and snippets.

@chabibnr
Created December 5, 2019 04:43
Show Gist options
  • Save chabibnr/4abd76f39f050fdc943721b553127c85 to your computer and use it in GitHub Desktop.
Save chabibnr/4abd76f39f050fdc943721b553127c85 to your computer and use it in GitHub Desktop.
Yii - enter as tab
$JS = <<<JS
$('body').on('keydown', 'input, select', function(e) {
if (e.key === "Enter") {
var self = $(this), form = self.parents('form:eq(0)'), focusable, next;
focusable = form.find('input,a,select,button,textarea').filter(':visible');
next = focusable.eq(focusable.index(this)+1);
if (next.length) {
next.focus();
} else {
form.submit();
}
return false;
}
});
JS;
$this->registerJs($JS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment