0
I have an application where I use zip code to be part of the registry. Only the CEP is enough and would need to be validated the CEP and at the end of the validation trigger a function. How can I do that?
html:
<input type="text" ng-model="endereco.cep" ng-keyup="pegaCep()" placeholder="CEP">
angular:
$scope.pegaCep = function () {
var cep = $scope.endereco.cep;
if(cep.length <= 8){
return
}else
if(cep.length == 9){
$http.get("http://www.vigilantescomunitarios.com/www/php/pegaCep.php?cep="+$scope.endereco.cep).success(function (endereco){
$scope.endereco = endereco;
});
}
}
It would have as [Edit] your post and add the code you are using, so we can better analyze and suggest where to apply the change. Thank you.
– David
I was able to do the validation, now I just need to make the function trigger when I finish typing the 9 digits.
– GustavoSevero
The function you say is to fill in the inputs with the address data?
– durtto
No, only the zip code. After the 9 characters of the zip code have been filled in, it triggers a function that fetches the other zip code data. What I have today, is, when leaving the zip code field, it searches the data, got @durtto?
– GustavoSevero
If the zip code is wrong, you issue a warning that is wrong?
– durtto
No, that I’m not validating.
– GustavoSevero
I got it. I put my solution in the post description.
– GustavoSevero
The ideal would be for you to use a Directive validation that would receive as an argument a callback to be called when the field was valid.
– Zignd
How could I do this @Zignd?
– GustavoSevero