0
Given a customer form, valid some mandatory fields. Mandatory fields that are not filled in are automatically highlighted on the page to make life easier for the user. So far 100%. As the user sees the remaining required fields and starts to fill in, automatically the highlight (bootstrap has-error class) disappears, normalizing that field.
It turns out that, with only one field of my form, this behavior does not occur, ie, the field is highlighted at the time of validation, when the user starts typing, it remains highlighted as if it was not filled.
Field on page (also validated if $Dirty is not filled in):
<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 the validation and highlight, the field works normally when typed (as the others). So it just doesn’t work when the first thing I do is click the save button, with that field still intact/untouched ($pristine)