i using following code "auto tab" working angularjs (automatically tabs user "title" textbox after max length met "name" textbox):
var app = angular.module('plunker', []); app.directive('autotabto', [function () { return { restrict: "a", link: function (scope, el, attrs) { el.bind('keyup', function(e) { if (this.value.length === this.maxlength) { var element = document.getelementbyid(attrs.autotabto); if (element) element.focus(); } }); } } }]); here html (with custom directives):
<customtextfield autotabto="variant.specs.title" ng-maxlength="20" customfield="variant.specs.name"></customtextfield> <customtextfield ng-maxlength="25" customfield="variant.specs.title"></customtextfield> would happen know doing wrong?
this piece of code should it. let's keep simple possible. :)
html:
<div ng-app="autofocus"> <label>name:</label> <input ng-model="maxlengthreach"></input> <br/><br/> <label>title:</label> <input autofocus-when></input> </div> javascript:
var app = angular.module('autofocus', []); app.directive('autofocuswhen', function () { return function (scope, element, attrs) { scope.$watch('maxlengthreach', function(newvalue){ if (newvalue.length >= 5 ) { element[0].focus(); } }); } }); jsfiddle: http://jsfiddle.net/gctvyfcz/1/
Comments
Post a Comment