Set enabled similar to preventDefault and preventEnterSubmit directives

This commit is contained in:
Bjarne Fyrstenborg
2020-09-02 11:48:29 +02:00
committed by Sebastiaan Janssen
parent 5927a16ae6
commit 5b82264c8e

View File

@@ -1,18 +1,28 @@
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();
});
}
};
};
});