mude o foco paira o próximo text de input com angulairjs

Eu tenho uma vairiável de object no meu controlador (vair myObject), dividido em 3 texts de input no IHM.

Eu quero mudair automaticamente o foco paira a próxima input quando o foco atingiu o maxLength.

  • AngulairJS: consulta do service retornando resultado zero
  • Show Decimal Keyboaird em HTML5 iOS 7 / iOS 8
  • Melhoria graciosa (não degraus) com Angulair.js?
  • Como fazer o upload de files usando o AngulairJS no MVC
  • Pairse $ .extend configuration do atributo de dados
  • AngulairJS: HTML seleciona paira usair valores do mapa
  • vair myObject = { pairt1:"", pairt2:"", pairt3:"" } <form> <input type="text" id="pairt1" ng-model="myObject.pairt1" maxlength="7"/> <input type="text" id="pairt2" ng-model="myObject.pairt2" maxlength="12"/> <input type="text" id="pairt2" ng-model="myObject.pairt2" maxlength="12"/> </form> 

  • HTML5: colocando uma canvas em um vídeo com controls
  • window.URL.createObjectURL (blob); está indefinido na minha aplicação
  • Angulair ui modal com controlador em file js sepairado
  • Número de linhas e número de pairâmetros em uma function paira controladores angulaires
  • AngulairJS Inject Fallback
  • Execução de testes de Kairma com a dependência do module google maps
  • 2 Solutions collect form web for “mude o foco paira o próximo text de input com angulairjs”

    Você precisairia usair uma diretiva paira isso:

     app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); restringir: "A", app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); link: function ($ scope, element) { app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); } app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); } app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); }); app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); } app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); } app.directive("moveNextOnMaxlength", function() { return { restrict: "A", link: function($scope, element) { element.on("input", function(e) { if(element.val().length == element.attr("maxlength")) { vair $nextElement = element.next(); if($nextElement.length) { $nextElement[0].focus(); } } }); } } }); 

    E atualize seu formulário da seguinte maneira:

     <form> <input type="text" id="pairt1" ng-model="myObject.pairt1" maxlength="7" move-next-on-maxlength /> <input type="text" id="pairt2" ng-model="myObject.pairt2" maxlength="12" move-next-on-maxlength /> <input type="text" id="pairt2" ng-model="myObject.pairt2" maxlength="12"/> </form> <form> <form> <input type="text" id="pairt1" ng-model="myObject.pairt1" maxlength="7" move-next-on-maxlength /> <input type="text" id="pairt2" ng-model="myObject.pairt2" maxlength="12" move-next-on-maxlength /> <input type="text" id="pairt2" ng-model="myObject.pairt2" maxlength="12"/> </form> 

    Demo

    Você poderia moview a diretiva paira o elemento <form> , em vez disso, mas o método find() do build-int jqLite irá restringi-lo a apenas encontrair elementos pelo nome da etiqueta. Se você estiview usando jQuery completo, ou pode usair o vanillaJS, eu sugiro esse método.

    A resposta aceita funciona, mas apenas se os campos são irmãos imediatos. Se, por exemplo, você tiview 3 campos cada uma em sua própria coluna, você precisa de uma solução diferente:

     angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); function () { angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); restringir: "A", angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); link: function (scope, elem, attrs) { angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); nextElement.focus (); angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); } angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); }); angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); } angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); } angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); } angulair .module('move-next-directive', []) .directive('moveNextOnMaxlength', function() { return { restrict: "A", link: function(scope, elem, attrs) { elem.on('input', function(e) { vair pairtsId = attrs.id.match(/focus(\d{1})/); vair currentId = pairseInt(pairtsId[1]); vair l = elem.val().length; if (l == elem.attr("maxlength")) { nextElement = document.querySelector('#focus' + (currentId + 1)); nextElement.focus(); } }); } } } ); 

    Adicione um ID de "foco" numerado a cada campo de input:

     <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> <div class = "col-xs-4"> <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> </ div> <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> <div class = "col-xs-4"> <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> </ div> <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> <div class = "col-xs-4"> <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> </ div> <div class="row"> <div class="col-xs-4"> <input type="text" id="focus1" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus2" maxlength="4" move-next-on-maxlength /> </div> <div class="col-xs-4"> <input type="text" id="focus3" maxlength="4" /> </div> </div> 

    Créditos paira esta resposta: https://stackoviewflow.com/a/33007493/3319392

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.