Set enabled similar to preventDefault and preventEnterSubmit directives
This commit is contained in:
committed by
Sebastiaan Janssen
parent
5927a16ae6
commit
5b82264c8e
@@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user