开发者

How can I use customer error messages on form fields generated by Ruby on Rails when using the jQuery validation plugin?

I'm trying to use jQuery Validation plugin with customer error messages in a form on my site. The way to specify customer messages is as follows:

$('#user_new').validate({
    messages: {
        user_email: {
        required: "dd ",
        email: "Please enter a valid email address, example: you@yourdomain.com"
    }
    }
});

This will apply the custom error messages to the input with the name of user_email. This code works okay. The problem is that the fields have names such as user[email] because they are generated by Rails using form_for. But this won't work:

$('#user_new').validate({
    messages: {
        user[email]: {
        required: "dd ",
        email: "Please enter a valid email address, example: you@yourdomain.com"
    }
    }
});

The user[email] part causes a javascript error. Has anyone got custom messages working on Rails generated input fields with th开发者_JAVA技巧is plugin? Thanks for reading.


Have you tried just quoting the javascript array keys?

messages: {
    "user[email]": {
    required: "dd ",
    email: "Please enter a valid email address, example: you@yourdomain.com"
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜