javascriptvalidationkendo-uikendo-validator

Validate particular field / particular rule using Kendo UI validation


Current I have the following custom rules to validate fields of my form.

Rules

$scope.validator = $("#frmPreregistration").kendoValidator({
    rules: {
        varifySsn: function (input) {
            var ret = true;
            if (input.is("[name=last4Ssn]") && $scope.Last4DigitsSsn != undefined ) {
                ret = $scope.validateSsnLast4Digit();
            }
            return ret;
        },
        varifyDob: function (input) {
            var ret = true;
            if (input.is("[name=dob]") && $scope.DateOfBirth != undefined ) {
                ret = $scope.validateDateOfBirth();
            }
            return ret;
        },
        varifyZipCode: function (input) {
            var ret = true;
            if (input.is("[name=zipCode]") && $scope.ZipCode != undefined ) {
                ret = $scope.validateZipCode();
            };
        return ret;
        }
    },
    messages: {
        varifySsn: $scope.resources.SsnLast4DigitDoesNotMatch,
        varifyDob: $scope.resources.DobNotMatchWithSelectedUserType,
        varifyZipCode: $scope.resources.ZipCodeNotMatchWithSelectedUserType,
    }
}).data("kendoValidator");

I am validating the form whenever user enters a value in any of the field in the form by $scope.validator.validate()

This is resulting in firing the rules for all the fields even before the user enters any value into it.

Question Is there any possibility that I can run a particular validation rule at a time or run validation for a particular field?


Solution

  • You can use validateInput for specific element.

    Example:

    $scope.validator.validateInput($("input[name=dob]"));
    

    to hide invalid message you can use hideMessages function

    $scope.validator.hideMessages();