0
Hello!
This script is used to turn capital letters into minuscule, keeping the first letter uppercase..
Put in line return str.match(/\S+\s*/g);
an error is occurring:
Uncaught TypeError: Canoot read property 'match'
Follow script and follow error print:
$(window).load(function() {
$.fn.capitalize = function() {
//palavras para serem ignoradas
var wordsToIgnore = ["DOS", "DAS", "de", "do"],
minLength = 3;
function getWords(str) {
return str.match(/\S+\s*/g);
}
this.each(function() {
var words = getWords(this.value);
$.each(words, function(i, word) {
// somente continua se a palavra nao estiver na lista de ignorados
if (wordsToIgnore.indexOf($.trim(word)) == -1 && $.trim(word).length > minLength) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase();
} else {
words[i] = words[i].toLowerCase();
}
});
this.value = words.join("");
});
};
//onblur do campo com classe .title
$('.title').on('blur', function() {
$(this).capitalize();
}).capitalize();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<input type="text" id="txt_nome_fantasia" class="nome_fantasia title form-control input-sm" autocomplete="off" placeholder="Nome Fantasia" >
Put the html to do the tests
– Phelipe
In some monento its variable str empty generating the error of the function match
– Otto
str has its value as null, so it is returning this error...
– Paz
@Otto even if it was empty it would not return the error, nor initialized it is.
– Paz
@Phelipe, I included the code as an example, see that the code does its job, but with error.
– Wagner Fillio