-1
I made a data editing screen, and the problem that is occurring is that when I put the zip code the address data appears, but the data, already filled out disappear! Can someone help me?
HTML:
<form name="formPerfilStartup">
<div class="row">
<div class="col-sm-12 col-md-12">
<p id="cep">CEP</p>
<input class="campoCep" type="text" name="cep" ng-model="perfilNovaStartup.cep">
<p id="cidade">Cidade</p>
<input class="campoCidade" type="text" name="localidade" ng-model="perfilNovaStartup.localidade">
<p id="estado">Estado</p>
<input class="selectEstado" type="text" name="uf" id="" ng-model="perfilNovaStartup.uf">
</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-6">
<p id="startup">Nome Startup</p>
<input class="startup" type="text" name="nomeStartup" ng-model="perfilNovaStartup.nomeStartup">
</div>
<div class="col-sm-6 col-md-6 ">
<p id="descricao">Descriçãp (resumo)</p>
<textarea name="resumo" cols="49" rows="5" ng-model="perfilNovaStartup.resumo"
placeholder="Sou engenheiro elétrico a 10 anos...">
</textarea>
</div>
</div>
</form>
JS that brings the cep data and other data:
app.controller("editarPerfilStartupCtrl", ['$scope', '$http', '$window', '$location', '$rootScope', '$routeParams', function ($scope, $http, $window, $location, $rootScope, $routeParams) {
$scope.idusuario = localStorage.getItem("startwe_idusuario");
$scope.usuario = localStorage.getItem("startwe_usuario");
$scope.idstartup = $routeParams.idstartup;
console.log(`id usuario ${$scope.idusuario}, usuario ${$scope.usuario}, id startup ${$scope.idstartup}`)
if(location.hostname == 'localhost'){
var urlPrefix = 'http://localhost:8888/sistemas/Webapps/Projetos/startWe/api/registerStartup.php';
var urlOptionPrefix = 'http://localhost:8888/sistemas/Webapps/Projetos/startWe/api/registerStartup.php?option=';
} else {
var urlPrefix = '';
}
$(document).ready(function(){
$('.campoCep').focusout(function(){
var valorCep = $('.campoCep').val();
$http.get('http://viacep.com.br/ws/'+valorCep+'/json/').then(function(response){
if(response.data.erro == true){
$scope.erro = 'CEP inexistente! Tente novamente.';
}
$scope.perfilNovaStartup = response.data;
})
})
});
var pegarStartup = function(){
var option = 'pegar startup';
var idstartup = $scope.idstartup;
$http.get(urlOptionPrefix + option + '&idstartup=' + idstartup).then(function(response){
//console.log(response.data)
$scope.perfilNovaStartup = response.data;
})
}
pegarStartup();
}]);
Thanks, I’ll try it
– GustavoSevero