diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbfocusbackwards.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbfocusbackwards.directive.js new file mode 100644 index 0000000000..c696c6cb28 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbfocusbackwards.directive.js @@ -0,0 +1,42 @@ +/** +@ngdoc directive +@name umbraco.directives: focusNow +@restrict A + +@description +Use this directive focus backwards in a list of elements. +You need to toggle the attribute's value everytime you delete an element to trigger the observe event. +$scope.focusMe = ($scope.focusMe === true)? false: true; + +

Example

+ +
+
+ + + + + + + +
+
+**/ +angular.module("umbraco").directive("focusBackwards", function ($timeout) { + return { + restrict: "A", + link: function (scope, element, attrs) { + attrs.$observe("focusBackwards", function (value) { + if (value === "true") { + $timeout(function () { + element.focus(); + }); + } else { + $timeout(function () { + element.focus(); + }); + } + }); + } + }; +}); diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.controller.js index 9621001d0c..6582e975e2 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.controller.js @@ -19,43 +19,50 @@ $scope.model.value.push({ value: "" }); } } - } + } - //TODO add focus to newly created text box or the first in line after deletion + //TODO add focus to newly created text box or the first in line after deletion $scope.addRemoveOnKeyDown = function (event, index) { var txtBoxValue = $scope.model.value[index]; - - switch (event.keyCode) { + + event.preventDefault(); + + switch (event.keyCode) { case 13: if ($scope.model.config.max <= 0 || $scope.model.value.length < $scope.model.config.max) { - $scope.model.value.push({ value: "" }); - + $scope.model.value.push({ value: "" }); + //Focus on the newly added value - $scope.focusMe = true; - } - break; + $scope.focusMe = false; + } + break; case 8: + var remainder = []; - if ($scope.model.value.length > 1) { - if (txtBoxValue.value === "") { + if ($scope.model.value.length > 1) { + if (txtBoxValue.value === "") { for (var x = 0; x < $scope.model.value.length; x++) { if (x !== index) { remainder.push($scope.model.value[x]); } } $scope.model.value = remainder; + + // The role of this statement is to trigger the observe event + $scope.focusMe = ($scope.focusMe === true) ? false : true; } } break; default: - } + } } - + $scope.add = function () { if ($scope.model.config.max <= 0 || $scope.model.value.length < $scope.model.config.max) { $scope.model.value.push({ value: "" }); + $scope.focusMe = false; } }; @@ -67,8 +74,9 @@ } } $scope.model.value = remainder; + $scope.focusMe = true; }; } -angular.module("umbraco").controller("Umbraco.PropertyEditors.MultipleTextBoxController", MultipleTextBoxController); +angular.module("umbraco").controller("Umbraco.PropertyEditors.MultipleTextBoxController", MultipleTextBoxController); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.html index e8ead14bc2..483bdee838 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.html @@ -1,20 +1,21 @@
-
-
- - - - - -
+
+
+ + + + +
- - - +
+ + +