Skip to content

Commit

Permalink
Set enabled similar to preventDefault and preventEnterSubmit directives
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarnef committed Aug 17, 2020
1 parent 7e02a94 commit 536ce85
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
angular.module("umbraco.directives")
.directive('umbAutoFocus', function($timeout) {

return function(scope, element, attr){
return function (scope, element, attrs) {
var update = function() {
//if it uses its default naming
if(element.val() === "" || attr.focusOnFilled){
if (element.val() === "" || attrs.focusOnFilled){
element.trigger("focus");
}
};

if (attr.umbAutoFocus !== "false") {
var enabled = true;
//check if there's a value for the attribute, if there is and it's false then we conditionally don't
//use auto focus.
if (attrs.umbAutoFocus) {
attrs.$observe("umbAutoFocus", function (newVal) {
enabled = (newVal === "false" || newVal === 0 || newVal === false) ? false : true;
});
}

if (enabled) {
$timeout(function() {
update();
});
}
};
};
});

0 comments on commit 536ce85

Please sign in to comment.