Last active
August 7, 2019 07:26
-
-
Save grekodev/879f5bcb44eb04caf8c26be58e94132b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js"></script> | |
<script> $(document).ready(() => { | |
ko.bindingHandlers.nextEnter = { | |
init: function (element, valueAccessor, allBindingsAccessor) { | |
$(element).on('keydown', 'input, select', function (e) { | |
var self = $(this), form = $(element), focusable, next; | |
if (e.keyCode == 13) { | |
focusable = form.find('input,a,select,button,textarea').filter(':visible'); | |
var nextIndex = focusable.index(this) == focusable.length - 1 ? 0 : focusable.index(this) + 1; | |
next = focusable.eq(nextIndex); | |
next.focus(); | |
return false; | |
} | |
}); | |
} | |
}; | |
ko.applyBindings({}); | |
});</script> | |
//use | |
<div class="form-horizontal" data-bind="nextEnter:true"> | |
// your_inputs | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment