Да, у нас есть директива для этого :) Исходный код (написанный в машинописи) на GitHub https://github.com/ST-Software/STAngular/blob/master/src/directives/SgUpperCase.ts
// Исправлена ошибка с курсором прыгая в конце
someModule.directive("sgUpperCase", [function() {
function getCaretPosition(inputField) {
// Initialize
var position = 0;
// IE Support
if (document.selection) {
inputField.focus();
// To get cursor position, get empty selection range
var emptySelection = document.selection.createRange();
// Move selection start to 0 position
emptySelection.moveStart('character', -inputField.value.length);
// The caret position is selection length
position = emptySelection.text.length;
}
else if (inputField.selectionStart || inputField.selectionStart == 0) {
position = inputField.selectionStart;
}
return position;
}
function setCaretPosition(inputElement, position) {
if (inputElement.createTextRange) {
var range = inputElement.createTextRange();
range.move('character', position);
range.select();
}
else {
if (inputElement.selectionStart) {
inputElement.focus();
inputElement.setSelectionRange(position, position);
}
else {
inputElement.focus();
}
}
}
return {
require: "^ngModel",
restrict: "A",
link: function (scope, elm, attrs, ctrl) {
var toUpperCase = function (inputValue) {
if (!inputValue)
return inputValue;
var modified = inputValue.toUpperCase();
if (modified !== inputValue) {
var position = getCaretPosition(elm[0]);
ctrl.$setViewValue(modified);
ctrl.$render();
setCaretPosition(elm[0], position);
}
return modified;
};
ctrl.$parsers.push(toUpperCase);
toUpperCase(scope[attrs.ngModel]); //Transform initial value
}
};
}]);
http://stackoverflow.com/questions/15242592/how-to-autocapitalize-an-input-field –
мне нужно все входные данные autocapitalize – Coder
Только первый символ или все символы? –