Skip to content

Instantly share code, notes, and snippets.

@rattanchauhan rattanchauhan/app.js
Last active Nov 6, 2016

What would you like to do?
AngularJs | Directive for Auto Focus Next element on Enter
var app = angular.module("myApp", []);
app.directive("moveNextOnEnter", function() {
return {
restrict: "A",
link: function($scope, element) {
element.bind("keyup", function(e) {
if (e.which == 13) {
var $nextElement =;
if($nextElement.length) {
<div ng-app="myApp">
<input type="text" id="part1" ng-model="myObject.part1" maxlength="7" move-next-on-enter />
<input type="text" id="part2" ng-model="myObject.part2" maxlength="12" move-next-on-enter />
<input type="text" id="part3" ng-model="myObject.part3" maxlength="12"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.