I created the following directive, for when a user types in the input to be converted to uppercase, however, when I need to edit this field to insert a word in the middle of what I had already typed, he plays the mouse cursor at the end of the input word .
Ex: Test0 Test2 When I enter another word Test0 Test1 Test2 he plays the course to the end of Test2 getting Test0 Test2 Test1.
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
var capitalize = function(inputValue) {
if(inputValue === undefined) inputValue = '';
var capitalized = inputValue.toUpperCase();
if(capitalized !== inputValue) {
modelCtrl.$setViewValue(capitalized);
modelCtrl.$render();
}
return capitalized;
};
modelCtrl.$parsers.push(capitalize);
capitalize(scope[attrs.ngModel]); // capitalize initial value
}
};