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 deleted file mode 100644 index c696c6cb28..0000000000 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbfocusbackwards.directive.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -@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 6582e975e2..254c905d4b 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 @@ -1,4 +1,4 @@ -function MultipleTextBoxController($scope) { +function MultipleTextBoxController($scope, $timeout) { $scope.sortableOptions = { axis: 'y', @@ -22,18 +22,23 @@ } //TODO add focus to newly created text box or the first in line after deletion - $scope.addRemoveOnKeyDown = function (event, index) { + $scope.addRemoveOnKeyDown = function (event, index) { + var txtBoxValue = $scope.model.value[index]; - event.preventDefault(); + var newItemIndex; + 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: "" }); + newItemIndex = $scope.model.value.length - 1; + //Focus on the newly added value - $scope.focusMe = false; + $scope.model.value[newItemIndex].hasFocus = true; } break; case 8: @@ -45,11 +50,19 @@ 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; + newItemIndex = $scope.model.value.length - 1; + + //Set focus back on false as the directive only watches for true + $scope.model.value[newItemIndex].hasFocus = false; + + $timeout(function () { + //Focus on the previous value + $scope.model.value[newItemIndex].hasFocus = true; + }); } } break; 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 483bdee838..7a6b4f4a29 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 @@ -4,7 +4,7 @@
+ ng-keyup="addRemoveOnKeyDown($event, $index)" focus-when="{{item.hasFocus}}"/>