Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validations of the input
Message
 
 
À
08/09/2017 03:42:41
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653867
Message ID:
01654119
Vues:
48
>>Looks like I got it although not 100% sure. Tired of debugging:
>>
>>
>> link: function ($scope, element, attrs, ngModel) {
>>               // if (element[0] && element[0].$touched) {
>>                    ngModel.$asyncValidators.smCodeUnique = function (modelValue, viewValue) {
>>
>>                        if (!viewValue || _.isEmpty(modelValue.trim())) {
>>                            return services.Q.when(true);
>>                        }
>>
>>                        var deferred = services.Deferred;
>>                        $log.info("Firing server-side validations for " + $scope.tableName + '.' + $scope.columnToTest);
>>                        let codeObject = {
>>                            id: $scope.primaryKey, tableName: $scope.tableName,
>>                            columnToTest: $scope.columnToTest, code: viewValue
>>                        };
>>                        return services.Http.put('api/items/checkCodeUniqueness', codeObject).then(
>>                            function (response) {
>>                                if (!response.data.isValid) {
>>                                    $scope.errorMessage = response.data.errorMessage;
>>                                    deferred.reject(response.data.errorMessage);
>>                                }
>>                                else {
>>                                    deferred.resolve(response.data);
>>                                }
>>                                return deferred.promise;
>>                            }
>>                        );
>>                    };
>>           //     }
>>            }
>Looks OK. but 'return deferred.promise' might be redundant ?

May be. The funny thing I realized few moments ago. I forgot about one extra scenario!!!!!!!! That simple scenario is when I am entering a new information. In this case nothing would prevent me (as of now) to enter same UPC and Barcode. I am wondering if I can simply handle this case before submitting and display error in a toaster then instead of trying an extra compare strings directive.

Will need something for case-insensitive string compare in JavaScript.

What do you think? Or should I be consistent and use another validator? And also, the scenario is even more complex for Matrix as there I am keeping an array of changed values, so I can potentially create many rows...

UPDATE. I was thinking I'll introduce objectToCompare inside that same directive. Do you think I can set both types of validators in one directive?
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform