Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validations of the input
Message
De
10/09/2017 05:14:55
 
 
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653867
Message ID:
01654187
Vues:
44
>>>My new question on that topic:
>>>
>>>https://stackoverflow.com/questions/46122489/preventing-extra-calls-of-asyncvalidators
>>
>>The jist of most of the links seems to be that you cannot rely on failed regular validators to prevent the async validators firing *on page load*.
>>
>>You probably need to add more logic to ngModel.$asyncValidators.smCodeUnique to ensure that situations that don't require the $http call return services.Q.when(true);
>
>Do you know how can I check inside the validator is the field was changed or not? Because I only want to fire the validators after I changed the field, not in the load. I think I tried using element[0].$dirty and that didn't work. I may try this again inside the validator's call.
>
>UPDATE. I think I was able to solve it although I don't know if this is a bullet proof solution or even a good one. Before declaring my directive I added this
>
> var services,
> $log, originalValue;
>
>And inside the code for the directive I added:
>
>
>ngModel.$asyncValidators.smCodeUnique = function (modelValue, viewValue) {
>                    if (!originalValue) {
>                        originalValue = modelValue;
>                    }
>                    if (!viewValue || _.isEmpty(modelValue.trim()) || modelValue==originalValue ) {
>                        return services.Q.when(true);
>                    }
>
>and then I was watching that it only executed when I changed my value manually (this is what I wanted).

Don't think you can stop the validation running on page load.. Above looks OK to me
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform