ASP.NET MVC2 - binding to client-side validation

I want to call some kind of custom code when client-side errors are updated using ASP.NET MVC2 client-side validation. I tracked this function that I want to connect to:

Sys.Mvc.FormContext.prototype = {

    // ...

    _displayError: function Sys_Mvc_FormContext$_displayError() {
        if (this._validationSummaryElement) {
            if (this._validationSummaryULElement) {
                Sys.Mvc._validationUtil.removeAllChildren(this._validationSummaryULElement);
                for (var i = 0; i < this._errors.length; i++) {
                    var liElement = document.createElement('li');
                    Sys.Mvc._validationUtil.setInnerText(liElement, this._errors[i]);
                    this._validationSummaryULElement.appendChild(liElement);
                }
            }
            Sys.UI.DomElement.removeCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryValidCss);
            Sys.UI.DomElement.addCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryErrorCss);
        }
    },

    // ...

}    

How can I override this function so that my code can

  • call to source function
  • then do another job.
0
source share
1 answer

Found.

<script type="text/javascript">
    $(function () {
        var old_displayError = Sys.Mvc.FormContext.prototype._displayError;
        Sys.Mvc.FormContext.prototype._displayError = function () {
            old_displayError.apply(this);
            // do other stuff here
        }
    });
</script>

I'm not used to overriding prototype functions, so I stumbled a bit.

0
source

Source: https://habr.com/ru/post/1777536/


All Articles