I have a special validation method that I use with the jquery validator. I am trying to get an error message for dynamic creation.
I have googled, and the answer that I saw most is shown in https://stackoverflow.com/a/212619/169 .
However, when I try to implement it myself, it does not work. It simply ignores my updated message and simply displays the original message.
Here is my code located inside the jquery.ready () function. What am I doing wrong?
Note: "g $" is our shortcut for jQuery.
var jsBlackoutDateMessage = "Tournaments cannot be scheduled on blackout dates.";
var jsBlackoutDateMessageFunction = function () {
return jsBlackoutDateMessage;
};
g$.validator.addMethod(
"notBlackoutDate",
function (value, element) {
var notBlackoutDate = true;
if (g$.inArray(value, jsBlackoutDates) != -1) {
notBlackoutDate = false;
}
if (notBlackoutDate == false) {
var year = new Date(g$.trim(g$('#txtDate').val())).getFullYear();
var blackoutDatesForYear = jsBlackoutDates.filter(function (item) {
return endsWith(item, year.toString());
})[0];
var blackoutDatesForYearMessage = [];
blackoutDatesForYearMessage.push("Tournaments cannot be scheduled on blackout dates.");
blackoutDatesForYearMessage.push("<ul>");
g$.each(blackoutDatesForYear, function (key, value) {
blackoutDatesForYearMessage.push("<li>");
blackoutDatesForYearMessage.push(new Date(value).toLocaleDateString());
blackoutDatesForYearMessage.push("</li>");
});
blackoutDatesForYearMessage.push("</ul>");
jsBlackoutDateMessage = blackoutDatesForYearMessage.join("");
}
return this.optional(element) || notBlackoutDate;
},
jsBlackoutDateMessageFunction
);
source
share