Validation Plugin - v1.11.0 Remote Validation Not Showing JS Message
Hi,
I am learning JQuery Validation. It's great. But I am having problems setting the message for remote validation through the rules and messages options. The message works fine when coming from the server. But I would prefer to keep all the messages together in javascript. If I do not use the server message, only 'false' appears in the error label. And the remote message set in js options is ignored. I have tried to follow the pattern found in the Milk demo. How can I fix this? The messages are being displayed in a container at the top of the page.
Thanks.
- $(document).ready(function () {
- $.validator.addMethod('noanon', function (value) {
- return value.toLowerCase().indexOf("anonymous") != 0;
- }, 'Do not hide behind the cover of anonymity');
- $('#commentForm').validate({
- errorContainer: '#errorbox',
- errorLabelContainer: '#errorbox ul',
- wrapper: 'li',
- highlight: function(element, errorClass){
- $(element).fadeOut(function () {
- $(element).addClass('invalidElem').fadeIn(1000);
- });
- },
- unhighlight: function(element, errorClass){
- $(element).removeClass('invalidElem');
- },
- rules: {
- name: {
- required: true,
- minlength: 2,
- noanon: true,
- remote: '/api/UserValidation'
- },
- email: {
- required: '#csub:checked',
- email: true
- },
- comment: { required: true }
- },
- messages: {
- comment: {
- required: 'This is a comment form. Your comment cannot be blank'
- },
- email: {
- required: "You must enter an email to get the newsletter?",
- email: 'Email addresses are of the form user@host.'
- },
- name: {
- required: 'Your name is required if you want to leave a comment.',
- minlength: $.format('You need at least {0} characters for your name.'),
- remote: $.format("'{0}' has been taken")
- }
- }
- });
- });