开发者

jQuery validator - Different error messages for same control

In my MVC validation I am using a calendar control and all validations work fine.

var today = $('#TodayDateHf').val();

$('#myform').validate({

    errorPlacement: $.calendars.picker.errorPlacement,

    rules: {

        Dat开发者_StackOverflow中文版eFrom: {
            cpDate:true,
            cpCompareDate: { notAfter: '#DateTo', 'notAfter' : today } 
        },
        DateTo: {
            cpDate:true,
            cpCompareDate: { notBefore: '#DateFrom' } 
        }     

    },

    messages: { 
        DateFrom: 'Please enter a valid date less than or equal to To date',
        DateTo: 'Please enter a valid date greater than or equal to From date'

    }

});

Everything works fine, but my problem is that I don't know how I can display different messages for same control.

For example, for DateFrom a rule is defined and there are two parameters in that rule, but it only displays the same error message. How can I display a different error messages based on the parameter evaluated?


You can use something like this

messages:{
                DateFrom:{
                    cpDate:"Message1",
                    cpCompareDate: "Message2"
                }

            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜