Overriding the validation method

Jun 18, 2013 at 4:02 AM
I am using twitter bootstrap css styling in my project. To show an error, this uses a class which is added to the parent dom element of the span which shows the error message.

Usually I would override the highlight and success functions of jQuery.validate to change the highlight logic.

e.g. $(item).parent().closest(".control-group").addClass("error")

How would I do this using DAValidation?
Coordinator
Jun 18, 2013 at 7:32 AM
You should be able to set CssClass(http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass.aspx) on validator control. Since error span is shown only when validation fails there should be no issues. In case when you need to change input style refer to the following question on SO http://stackoverflow.com/questions/1301508/change-textboxs-css-class-when-asp-net-validation-fails.

From: jdarbyshire
Sent: 18.06.2013 7:02
To: [email removed]
Subject: Overriding the validation method [davalidation:447360]

From: jdarbyshire

I am using twitter bootstrap css styling in my project. To show an error, this uses a class which is added to the parent dom element of the span which shows the error message.

Usually I would override the highlight and success functions of jQuery.validate to change the highlight logic.

e.g. $(item).parent().closest(".control-group").addClass("error")

How would I do this using DAValidation?
May 27, 2014 at 7:34 PM
I use this:

// Add server side validation style
$("span[data-val='true']").each(function (e) {

    if ($(this).is(":visible")) {
        $(this).closest('.form-group').addClass("has-error");
    }
});
// Add client side validation style
(function ($) {

    if (window.ValidatorUpdateDisplay) {
        var proxied = window.ValidatorUpdateDisplay;

        window.ValidatorUpdateDisplay = function () {
            onBefore(arguments);

            var result = proxied.apply(this, arguments);

            onAfter(arguments);

            return result;
        };

        var onBefore = function (arguments) {

        };

        var onAfter = function (arguments) {
            var control = document.getElementById(arguments[0].controltovalidate);
            var validators = control.Validators;
            var isValid = true;

            for (var i = 0; i < validators.length; i++) {
                if (!validators[i].isvalid) {
                    isValid = false;
                    break;
                }
            }

            if (isValid) {
                var group = $(control).closest('div.form-group');
                if (group.find('span.field-validation-error').length > 0) {
                    group.removeClass('has-error');
                    group.addClass('has-success');
                }

            } else {
                var group = $(control).closest('div.form-group');
                if (group.find('span.field-validation-error').length > 0) {
                    group.removeClass('has-success');
                    group.addClass('has-error');
                }
            }

            /* Update fancybox size if validation occurs inside pop-up */
            if (parent.$.fancybox != null && parent.$.fancybox.isOpen) {
                parent.$.fancybox.update();
            }

        };
    }
})(jQuery);