@sinkz wrote:
I have a form which is within a modal:
<script id="my-modal.html" type="text/ng-template"> <ion-modal-view class="back"> <ion-header-bar class="bar-dark"> <h1 class="title">Novo Usuário</h1> </ion-header-bar> <ion-content > <form name="usuarioForm" role="form" novalidate=""> <label class="item item-input" style="margin-left:10px;margin-right:10px;margin-top:8px" ng-class="{'has-errors' : usuarioForm.codigo.$invalid, 'no-errors' : usuarioForm.codigo.$valid}"> <input type="text" name="codigo" placeholder="Código" ng-model="usuario.codigo" ng-minlength="3" ng-maxlength="20" ng-blur="getUsuario(usuario, $event)" required> </label> <div class="error-container" ng-show="usuarioForm.codigo.$error" ng-messages="usuarioForm.codigo.$error"> <div ng-messages-include="error-list.html"></div> </div> <label class="item item-input" style="margin-left:10px;margin-right:10px;margin-top:5px"> <input type="text" placeholder="Nome" ng-model="usuario.nome" ng-required="true"> </label> </div> <button class="button button-block button-positive" type="submit" ng-click="salvar(usuario)" ng-disabled="usuarioForm.$invalid"><i class="ion-checkmark" ></i> Cadastrar </button> <button class="button button-block button button-positive" ng-click="closeModal()" ><i class="ion-close"></i> Voltar </button> </form> </ion-content> </ion-modal-view> </script>
But when I try to clean it through setPristine, i got this error Error:
$scope.usuarioForm is undefined
This is my function:
$scope.salvar = function(usuario) { usuarioAPI.saveUsuario(usuario).success(function(data) { console.log("Salvar!"); delete $scope.usuario; $scope.usuarioForm.$setPristine(); $scope.closeModal(); }) .error(function(response, status) { console.log("erro " + status); }); }
Someone could help me clean it?
Posts: 2
Participants: 2