Given a client form, valid fields are required. Required fields that are not filled in are automatically highlighted on the page to make the user's life easier. So far 100%. As the user sees the remaining required fields and starts to populate, the highlight (has-error class of the bootstrap) disappears, normalizing that field.
It happens that with only one field on my form, this behavior does not occur, that is, the field is highlighted at the time of the validation, when the user starts typing, it remains highlighted as if it were not filled. >
Field on page (also validated if $ dirty and not populated):
<div class="form-group col-md-6" ng-class="{'has-error': vm.clienteForm.nome.$invalid && vm.clienteForm.nome.$dirty}">
<label for="nome">Nome:</label>
<input type="text" id="nome" name="nome" class="form-control" ng-model="vm.cliente.nome" required />
</div>
Script that validates all fields when saving:
function salva(cliente) {
if (vm.clienteForm.$valid) {
ClienteService.salva(cliente)
.then(function () {
$location.path('/clientes');
});
} else {
$('[required]').filter(function () {
return !this.value.trim();
}).parent().addClass('has-error');
MensagensService.mostraMsgErro();
}
}
ps: If I type anything in this field and then delete it, then I click save, after validation and highlighting, the field works normally when typed (depending on the others). So, it just does not work when the first thing I do is click the save button, with that field still virgin / intact ($ pristine)