Hide validation message after form submission, Angularjs!

Asked

Viewed 104 times

0

I have a form with validations on Angular but when I do send I give a delete $scope.msg to delete inputs, but when I do so, the validation files appear.

How do I stop when sending the form, the fields are cleared and the messages do not appear?

  • Are you using what kind of validation?

  • You cannot trigger the occultation of the elements in the response of this call ?

  • how to trigger?

  • use direct angular validation => ng-show="contactForm.nome.$invalid && !contactForm.nome.$pristine"

1 answer

2

The correct way to restore and validate an angular form is with ng-messages

angular.module("seuApp", ["ngMessages"]);

Where your form is referenced in controller for 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 the same must be restored with setPristine

$scope.add = function (el) {
                $scope.testes.push(angular.copy(el));
                delete $scope.el;
                $scope.teste.$setPristine();
            };

Browser other questions tagged

You are not signed in. Login or sign up in order to post.