Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validations of the input
Message
De
06/09/2017 06:12:01
 
 
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653867
Message ID:
01654032
Vues:
49
Only had time for a quick look.

If you use the default angular $asyncValidator then there's a built behaviour which means a resolved promise translates to valid and a rejected promise to invalid (so basically a true/false option) but I don't see how you could access any parameters passed in the resolve() or reject() (e.g. messages from server).

OTOH, a role your own directive (as in the examples in my link) would allow you to display the messages.

But the obvious disadvantage with the latter is that it would not have the angular behaviour of only running if all local validations have succeeded - which may or may not be a factor in your situation......


>I read now that article
>
>https://www.yearofmoo.com/2014/09/taming-forms-in-angularjs-1-3.html
>
>and also took a quick peak at the directive ng-remote-validation.
>
>I think I'd like to create the directive myself and the examples in the article seem relatively straightforward, I hope to be able to follow them tomorrow but one thing I'm not exactly clear how to implement. Suppose my API call will return IsValid = false errorMessage = 'Some lengthy message'. I see in that article about setting validators, but I'm not clear about the validation message.
>
>Thanks again.
>
>
>>>>Why return an error - I'd just return true/false.
>>>>
>>>>ng-change should be ok but probably a good idea to add a debounce to the model options. Ideally something like:
ng-model-options="{ updateOn: 'default blur', debounce: {'default': 1000, 'blur': 0} }"
This would perform the check after 1sec. of inactivity, or immediately when the focus is moved.
>>>
>>>I'd like to return the message explaining where this barcode is already used (e.g. which item). Here is how I'd like the interface to look (see attached).
>>>
>>>So, as I understand it will involve setting the error (validation). This is the part I'm not 100% sure how to implement although I did a bit of research.
>>>
>>>https://stackoverflow.com/questions/16168355/angularjs-server-side-validation-and-client-side-forms
>>>
>>>There was a link in that discussion I planned to follow up but was very busy with other work. May be you have examples of how to do that part.
>>>
>>>Thanks.
>>
>>So have the server return a string describing the problem. I don't think you should (or need) treat a problem as an error.
>>
>>Two examples here (using directives) that might be worth looking at as an approach to client side handling:
>>https://stackoverflow.com/questions/12864887/angularjs-integrating-with-server-side-validation
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform