Skip to content

Commit

Permalink
[Fix] angular-ui#317: Applying ui-mask on multiple fields on a form s…
Browse files Browse the repository at this point in the history
…ets focus on the last masked input box automatically
  • Loading branch information
asadighi committed Jun 15, 2015
1 parent 6ea34c8 commit 3f62d88
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions modules/mask/mask.js
Expand Up @@ -437,11 +437,13 @@ angular.module('ui.mask', [])
if (input.selectionStart !== undefined) {
return input.selectionStart;
} else if (document.selection) {
// Curse you IE
input.focus();
var selection = document.selection.createRange();
selection.moveStart('character', input.value ? -input.value.length : 0);
return selection.text.length;
if ($(input).is(':focus')) {
// Curse you IE
input.focus();
var selection = document.selection.createRange();
selection.moveStart('character', input.value ? -input.value.length : 0);
return selection.text.length;
}
}
return 0;
}
Expand All @@ -452,16 +454,20 @@ angular.module('ui.mask', [])
return; // Input's hidden
}
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(pos, pos);
if ($(input).is(':focus')) {
input.focus();
input.setSelectionRange(pos, pos);
}
}
else if (input.createTextRange) {
// Curse you IE
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
if ($(input).is(':focus')) {
// Curse you IE
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
}

Expand Down

0 comments on commit 3f62d88

Please sign in to comment.