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:
01654177
Vues:
49
UPDATE. I re-designed this in accordance to https://codepen.io/kvangrae/pen/BjxMWR
 link: function ($scope, element, attrs, ngModel) {
                if (!ngModel) return;

                originalValue = ngModel.$modelValue;

                $scope.$watch('valueToCompare', function (valueToCompare) {
                    // watches for changes from valueToCompare binding
                    ngModel.$validate();
                });

                ngModel.$validators.codeUnique = function (modelValue, viewValue) {
                    let status = true;
                    if (_.isEmpty(viewValue.trim()) || _.isEmpty($scope.valueToCompare.trim())) {
                        status = true;
                    }
                    else {
                        if (viewValue.trim().toUpperCase() === $scope.valueToCompare.trim().toUpperCase()) {
                            status = false;
                        }
                    }
                    return status;
                };
There is still yet a problem but I think I'll leave this one. Say, I entered the same code in UPC as in the barcode and then deleted the barcode value. I still get the error now coming from asyncValidators saying that the code already exists in the barcode for this item. I think making it smarter would be tough.

---------------------------------------
I found another problem. I was able to solve the problem with firing my asyncValidators. But now the problem is here
if (_.isObject($scope.objectToCompare)) {
                    ngModel.$validators.codeUnique = function (modelValue, viewValue) {
                        let status = true;
                        if (_.isEmpty(viewValue.trim()) || _.isEmpty($scope.objectToCompare.$modelValue.trim())) {
                            status = true;
                        }
                        else {
                            if (viewValue.trim().toUpperCase() === $scope.objectToCompare.$modelValue.trim().toUpperCase()) {
                                status = false;
                            }
                        }
                        return status;
                    };
                }
I have two controls on the form - UPC and Barcode and I validate each against the other. So, suppose I entered the same value in UPC as in my barcode. I got the error message on UPC.

Now, I remove value from barcode (thus making UPC unique). Unfortunately, the invalid message still stays on my UPC.

Do you see how can I make it clear?
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