I have a form where some inputs are accustomed to a custom verifier through instructions. The input should be valid on blur, and this is done through such asynchronous REST API calls.
HTML:
& lt; Input type = "text" valid - this ng-model = "ThisField" ng-model-option = "{'updateOn': 'blur'}" ng-pattern = "some patterns" /> Director (Short for Short): Return {Access: 'A', Required: 'NGModel', Scope: Wrong, Link: Work (Scope, AMM, ET's, NGModel) {NGMdale. $ AsyncValidators.validate Returns $ q.defer = this = function (modelvall, vvl) {if (! Model with AND! VAL)! // API service returns promise from API. Some validity (); }; }}; The above code works entirely, but the Verification job notices directly to the Hikish line below the signature: if (modelVal & amp; ; ViewVal) return $ q.defer (). promise;
Without that line, the collier attempts to validate the field immediately on the application load rather than the blur. This is a problem because the actual verification code parsing some string, and modelVal
and both viewVal
are undefined
, javascript throws an error.
I have tried to disable the functionality that loads the data when the application loads and the error still occurs. The patterns specified in ng-pattern
, however, Strong> does respect my wishes and only validates on field blur - this page does not attempt to validate on load. Is there any way to tell any kind of angular to validate only on blur, or to stop trying to validate as a page load? Or am I using $ asyncValidators
incorrectly?
each attr. The signs of the input validation inspection for instructions such as ngPattern. You can see that the Directive function in their pattern
I am trying to find a way around it because I use several input validations (pattern, maximum length, required, etc.) and my $ asyncValidators trigger during load 7 times. It executes the web server for each trigger.
Solution:
- Cache web method feedback
- Attach your handler after page load (or some types of flags)
-
Bake ngPattern test in your async handler I'll probably go with this one.
ngModel $ AsyncValidators.validate this = function (modelVal, viewVal) {var deferred = $ q.defer (); If (! ModelVell & WatchWall) deferred.resolve (); And if (! MyPattern.test (modelVal) deferred.reject (); Else api.doSomeValidation (value) Then (work (result) (deferred.resolve ();}, function (result) {deferred.reject ();}) return deferred.promise;};
Hope this helps because I am in the same boat looking for a solution.
Comments
Post a Comment