I have a form with validations in Angular but when I send it I give%% to delete the inputs, but when I do this the validation alerts appear.
How do I send the form, the fields are cleared and the messages do not appear?
I have a form with validations in Angular but when I send it I give%% to delete the inputs, but when I do this the validation alerts appear.
How do I send the form, the fields are cleared and the messages do not appear?
The correct way to restore and validate an angled form is with ng-messages
angular.module("seuApp", ["ngMessages"]);
Where your form
is referenced in controller
by name
example ...
<form name="teste">
<input class="form-control" type="text" ng-model="testes.nome" name="nome" placeholder="Nome" ng-required="true" ng-minlength="10"/>
</form>
<div ng-messages="teste.nome.$error" class="alert alert-danger">
<div ng-message="required">
Por favor, preencha o campo nome!
</div>
<div ng-message="minlength">
O campo nome deve ter no mínimo 10 caracteres.
</div>
</div>
After submission, it should be restored with setPristine
$scope.add = function (el) {
$scope.testes.push(angular.copy(el));
delete $scope.el;
$scope.teste.$setPristine();
};