<commit_before>var app = angular.module('form-example1', ['validation']);

var INTEGER_REGEXP = /^\-?\d+$/;

app.controller("Controller", function ($scope, RemoteValidations) {
    $scope.disposableEmail = RemoteValidations.disposableMail;
    $scope.duplicateEmail = RemoteValidations.duplicateMail;
});
app.factory('RemoteValidations', function ($timeout) {
    return {
        disposableMail: function (email) {
            if (!email) return true;
            return email.indexOf('@mailinator.com') >= 0 ? false : true;
        },
        duplicateMail: function (email) {
            return $timeout(function () {
                return ['<EMAIL>', '<EMAIL>', '<EMAIL>'].indexOf(email) >= 0 ? true : false;
            }, 2000);
        }
    };
});
angular.module('validation', [])
    .directive('customValidator', [function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, elm, attr, ngModelCtrl) {
            var validateFunctionNames = attr["validateFunctions"].split(",");
            ngModelCtrl.$parsers.push(function (value) {
                var hasErrors = false;
                angular.forEach(validateFunctionNames, function (functionName) {
                    if (!scope[functionName]) {
                        console.log('There is no function with' + functionName + ' available on the scope. Please make sure the function exists on current scope or its parent.');
                    } else {
                        var result = scope[functionName](value);
                        if (result === false) {
                            ngModelCtrl.$setValidity(attr.customValidator, false);
                            hasErrors = true;
                        }
                    }
                });
                return hasErrors ? undefined : value;
            });
        }
    };
}])
    .directive('customRemoteValidator', [function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, elm, attr, ngModelCtrl) {
            var validateFunctionNames = attr["validateFunctions"].split(",");
            ngModelCtrl.$parsers.push(function (value) {
                angular.forEach(validateFunctionNames, function (functionName) {
                    if (!scope[functionName]) {
                        console.log('There is no function with' + functionName + ' available on the scope. Please make sure the function exists on current scope or its parent.');
                    } else {
                        var result = scope[functionName](value);
                        if (result.then) {
                            result.then(function (data) { //For promise type result object
                                ngModelCtrl.$setValidity(attr.customValidator, data);
                            }, function (error) {
                                ngModelCtrl.$setValidity(attr.customValidator, false);
                            });
                        }
                    }
                });
                return value;
            });
        }
    };
}])
    .directive('validationMessages', function () {
    return {
        scope: {
            modelController: '='
        },
        restrict: 'EA',
        link: function (scope, elm, attrs) {
            if (!scope.modelController) {
                console.log('Requires a html attribute data-model-controller. This should point to the input field model controller.');
            }
            scope.$watch('modelController.$error', function (newValue) {
                if (newValue) {
                    scope.errorMessages = [];
                    angular.forEach(newValue, function (value, key) {
                        if (value && attrs[key + 'Error']) {
                            scope.errorMessages.push(attrs[key + 'Error']);
                        }
                    });
                }
            }, true);
        },
        template: '<div><small class="error" ng-repeat="message in errorMessages" ng-show= "!modelController.$pristine && $first" class="warning">{{message}}</small></div>'
    }
})
    .directive('ngUpdateOnBlur', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        priority: '100',
        link: function (scope, elm, attr, ngModelCtrl) {
            if (attr.type === 'radio' || attr.type === 'checkbox') return;

            elm.unbind('input').unbind('keydown').unbind('change');
            elm.bind('blur', function () {
                scope.$apply(function () {
                    ngModelCtrl.$setViewValue(elm.val());
                });
            });
        }
    };
});<commit_msg>Fixed issues with custom validators<commit_after>var app = angular.module('form-example1', ['validation']);

var INTEGER_REGEXP = /^\-?\d+$/;

app.controller("Controller", function ($scope, Validations) {
    angular.extend($scope, Validations);
});
app.factory('Validations', function ($timeout) {
    return {
        disposableMail: function (email) {
            if (!email) return true;
            return email.indexOf('@mailinator.com') >= 0 ? false : true;
        },
        spamWarning: function (email) {
            if (!email) return true;
            return email.indexOf('@hotmail.com') >= 0 ? false : true;
        },
        duplicateMailRemoteCheck: function (email) {
            return $timeout(function () {
                return ['<EMAIL>', '<EMAIL>', '<EMAIL>'].indexOf(email) >= 0 ? true : false;
            }, 2000);
        }
    };
});
angular.module('validation', [])
    .directive('customValidator', [function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, elm, attr, ngModelCtrl) {
            var validateFunctionNames = attr["validateFunctions"].split(",");
            var validatorNames = attr["customValidator"].split(",");
            ngModelCtrl.$parsers.push(function (value) {
                var hasErrors = false;
                angular.forEach(validateFunctionNames, function (functionName, index) {
                    if (!scope[functionName]) {
                        console.log('There is no function with name ' + functionName + ' available on the scope. Please make sure the function exists on current scope or its parent.');
                    } else {
                        var result = scope[functionName](value);
                        if (result && result != false) {
                            ngModelCtrl.$setValidity(validatorNames[index], true);
                        } else {
                            ngModelCtrl.$setValidity(validatorNames[index], false);
                            hasErrors = true;
                        }

                    }
                });
                return hasErrors ? undefined : value;
            });
        }
    };
}])
    .directive('customRemoteValidator', [function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, elm, attr, ngModelCtrl) {
            var validateFunctionNames = attr["validateFunctions"].split(",");
            var validatorNames = attr["customRemoteValidator"].split(",");
            ngModelCtrl.$parsers.push(function (value) {
                angular.forEach(validateFunctionNames, function (functionName, index) {
                    if (!scope[functionName]) {
                        console.log('There is no function with ' + functionName + ' available on the scope. Please make sure the function exists on current scope or its parent.');
                    } else {
                        var result = scope[functionName](value);
                        if (result.then) {
                            result.then(function (data) { //For promise type result object
                                ngModelCtrl.$setValidity(validatorNames[index], data);
                            }, function (error) {
                                ngModelCtrl.$setValidity(validatorNames[index], false);
                            });
                        }
                    }
                });
                return value;
            });
        }
    };
}])
    .directive('validationMessages', function () {
    return {
        scope: {
            modelController: '='
        },
        restrict: 'EA',
        link: function (scope, elm, attrs) {
            if (!scope.modelController) {
                console.log('Requires a html attribute data-model-controller. This should point to the input field model controller.');
            }
            scope.$watch('modelController.$error', function (newValue) {
                if (newValue) {
                    scope.errorMessages = [];
                    angular.forEach(newValue, function (value, key) {
                        if (value && attrs[key + 'Error']) {
                            scope.errorMessages.push(attrs[key + 'Error']);
                        }
                    });
                }
            }, true);
        },
        template: '<div><small class="error" ng-repeat="message in errorMessages" ng-show= "!modelController.$pristine && $first" class="warning">{{message}}</small></div>'
    }
})
    .directive('ngUpdateOnBlur', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        priority: '100',
        link: function (scope, elm, attr, ngModelCtrl) {
            if (attr.type === 'radio' || attr.type === 'checkbox') return;

            elm.unbind('input').unbind('keydown').unbind('change');
            elm.bind('blur', function () {
                scope.$apply(function () {
                    ngModelCtrl.$setViewValue(elm.val());
                });
            });
        }
    };
});
{'fraction_non_alphanumeric': 0.1293032786885246, 'fraction_numerical': 0.002151639344262295, 'mean_word_length': 1.5987752928647498, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3360133', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2334, 'n_words': 537}