views:

109

answers:

1

Hello, I've got a little problem here. I've got the following rule for one of my fields:

StartDate: {
    required: isDelayed,
    dateRU: true
}

isDelayed() returns false, so I guess StartDate field should be optional. However if I check it inside my dateRU method:

$.validator.addMethod(
    "dateRU",
    function(value, element) {
        return this.optional(element) || isValidDate($.trim(value));
    },
    "Date is incorrect"
);

this.optional(element) always returns false for StartDate. I can't figure out what's wrong. Any ideas?

UPD. Does optional() returns true only if element is not required AND IS EMPTY? 'Cause that may be my problem.

A: 

My guess would be your isDelayed function is not returning what you expect, making it required. I tested your code using this and it works:

function isDelayed() { return false; }

You can see a full working demo here, try and see what's different in your code from the demo, my best guess is that isDelayed() method, or a difference between your actual and posted code.

Nick Craver