From 9707d6bda13e2d18473685ec12b3dd5d2a68db3c Mon Sep 17 00:00:00 2001 From: Alexander Kudryashov Date: Tue, 19 May 2015 17:48:58 +0300 Subject: [PATCH] Fix: appendToBody with jQuery < 1.10.0; stealing focus #944 .relpaceWith in jQuery (version less then 1.10) doesn't work properly and as so, ui-select with 'appendToBody=true' doesn't display selected value. Use .after() and .remove() instead of .replaceWith() to avoid this issue. fix for #944: Don't restore focus if it was moved out of select (irregardles of target element). Otherwise it looks too confusing when clicking on links or any other control that is not an input/button/textarea. --- src/uiSelectDirective.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 285cfb4ac..3d3603aef 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -190,17 +190,7 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - var skipFocusser; - if (!$select.skipFocusser) { - //Will lose focus only with certain targets - var focusableControls = ['input','button','textarea','select']; - var targetController = angular.element(e.target).controller('uiSelect'); //To check if target is other ui-select - skipFocusser = targetController && targetController !== $select; //To check if target is other ui-select - if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea - } else { - skipFocusser = true; - } - $select.close(skipFocusser); + $select.close(true); scope.$digest(); } $select.clickTriggeredSelect = false; @@ -298,7 +288,8 @@ uis.directive('uiSelect', } // Move the dropdown element back to its original location in the DOM - placeholder.replaceWith(element); + placeholder.after(element); + placeholder.remove(); placeholder = null; element[0].style.position = '';