I have this directive:
(function () {
'use strict';
var app = angular.module('myAppName');
app.directive('smFocus', [ '$timeout', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element) {
scope.$on('sm:focus', function () {
$timeout(function() {
element[0].focus();
}, 10);
});
}
};
}]);
})();
I also have these two controls:
<input type="text"
name="nickname"
id="nickname"
ng-model="currentDynamicRule.nickname"
class="form-control"
ng-disabled="!isNew"
placeholder="Nickname"
required
ng-maxlength="10"
sm-focus />
and another one
<input type="text" name="descrip" id="descrip" ng-model="currentDynamicRule.descrip" class="form-control"
placeholder="Description" required ng-maxlength="30"
sm-focus />
So, two controls where the first one is only enabled when it's a new row (disabled in Edit mode). I want to have the first control focused when it's a new record and the second control focused when it's in edit mode.
I am using ASP.NET MVC. Right now in both edit and new modes I have the second control focused. I am not sure how to make this focus conditional.