MVC Adding methods into jquery.validate.unobtrusive.js

前端 未结 3 1140
醉酒成梦
醉酒成梦 2021-02-03 10:17

I recently had a question on getting checkbox validation working on the client side within a MVC project. This question was successfully answered, but raised another query.

3条回答
  •  执笔经年
    2021-02-03 10:44

    I have no problem adding this code to an external javascript file, which i pilfered from This site

    // Custom validator for checkboxs
    jQuery.validator.unobtrusive.adapters.add("brequired", function (options) {    
        //bool-required for checkboxes    
        if (options.element.tagName.toUpperCase() == "INPUT" && 
            options.element.type.toUpperCase() == "CHECKBOX") 
        {
            options.rules["required"] = true;        
            if (options.message) {
                options.messages["required"] = options.message;
            }
        }
    });
    

    Are you certain that you put your script AFTER the jquery scripts in your page? Mine is the last in the list.

提交回复
热议问题