Created
April 5, 2016 11:57
-
-
Save rbezerra/6c2c726a18e1b7b1705ff158d9d1ad40 to your computer and use it in GitHub Desktop.
asyncValidator não está validando
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(){ | |
| 'use strict'; | |
| angular | |
| .module('estacionamento') | |
| .directive('adesivoValidator', adesivoValidator); | |
| adesivoValidator.$inject = ['$http', '$q']; | |
| function adesivoValidator($http, $q){ | |
| return { | |
| restict: 'A', | |
| require: 'ngModel', | |
| link: function(scope, element, attrs, ngModel){ | |
| ngModel.$asyncValidators.adesivoValidator = function(cod_adesivo){ | |
| return $http | |
| .get('/estacionamento/public/api/veiculos/adesivo/'+cod_adesivo) | |
| .then(function(response){ | |
| if(response.data.adesivoCadastrado){ | |
| $q.reject("Adesivo já está sendo utilizado!"); | |
| }else{ | |
| true; | |
| } | |
| }, function(error){ | |
| return error; | |
| }); | |
| } | |
| } | |
| }; | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <input type="text" name="cod_adesivo" ng-model="vm.cadastroASerAprovado.veiculo.cod_adesivo" ng-pattern="/^[0-9]{4}$/" class="form-control" placeholder="Nº do Adesivo" adesivo-validator ng-model-options="{ updateOn: 'default blur', debounce: {'default': 300, 'blur': 0} }" required> | |
| <div class="error-messages" ng-messages="formAprovaCadastro.cod_adesivo.$error" ng-if="formAprovaCadastro.cod_adesivo.$touched || formAprovaCadastro.$submitted"> | |
| <div ng-message="required">Nº do Adesivo é um Campo Obrigatório!</div> | |
| <div ng-message="pattern">Valor Inválido</div> | |
| <div ng-message="adesivo-validator">Este adesivo já está sendo utilizado</div> | |
| <div ng-if="formAprovaCadastro.cod_adesivo.$error">{{formAprovaCadastro.cod_adesivo.$error}}</div> | |
| </div> | |
| <div class="error-messages" ng-messages="formAprovaCadastro.cod_adesivo.$pending"> | |
| <div ng-message="formAprovaCadastro.cod_adesivo.$pending"> | |
| Pesquisando... | |
| </div> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment