0
I created the following directive, so when a user type in the input is converted to uppercase, however, when I need to edit this field to insert a word in the middle of what I had already typed it plays the mouse cursor at the end of the input word.
Ex: Teste0 Teste2 When I enter another word Teste0 Teste1 Teste2 it plays the course to the end of Teste2 getting Teste0 Teste2teste1.
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
}
};
It worked, but I had to put this: element.css("text-Transform","uppercase");
– Felipe j.lemos
Capitalize
leaves only the first letter uppercase.– celsomtrindade