From 536ce855c4545ead82cea77b4013bf9010a8687b Mon Sep 17 00:00:00 2001 From: Bjarne Fyrstenborg Date: Mon, 17 Aug 2020 15:47:09 +0200 Subject: [PATCH] Set enabled similar to preventDefault and preventEnterSubmit directives --- .../components/forms/umbautofocus.directive.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautofocus.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautofocus.directive.js index eb3503f799b3..f53cddbc9873 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautofocus.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautofocus.directive.js @@ -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(); }); } - }; + }; });