MVC unobtrusive validation on checkbox not working

后端 未结 6 771
执笔经年
执笔经年 2020-12-04 08:03

I\'m trying to implement the code as mentioned in this post. In other words I\'m trying to implement unobtrusive validation on a terms and conditions checkbox. If the user

6条回答
  •  情歌与酒
    2020-12-04 08:31

    Sniffer,

    In addition to implementing Darin's solution, you also need to modify the file jquery.validate.unobtrusive.js. In this file, you must add a "mustbetrue" validation method, as follows:

    $jQval.addMethod("mustbetrue", function (value, element, param) {
        // check if dependency is met
        if (!this.depend(param, element))
            return "dependency-mismatch";
        return element.checked;
    });
    

    Then (I forgot to add this at first), you must also add the following to jquery.validate.unobtrusive.js:

    adapters.add("mustbetrue", function (options) {
        setValidationValues(options, "mustbetrue", true);
    });
    

    counsellorben

提交回复
热议问题