Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validations of the input
Message
 
 
À
09/09/2017 04:22:47
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653867
Message ID:
01654176
Vues:
54
>>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).
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform