I have two date fields:
1. From:
This date picker should only allow you to select the 1st or 16th of every month
2. To:
This date picker should only allow you to select the 15th or last day of every month
$(document).ready(function(){
$("#q9").click(function(){
function isCorrectDate(n) {
var t = n.getDay();
var d = n.getDate();
return (d==1 || d==16);
}
function checkDate(n) {
return[isCorrectDate(n),""];
}
function checkField(input, inst) {
if ($(input).closest('li').hasClass('myDate')) {
$(input).datepicker("option", {beforeShowDay: checkDate});
}
}
$.datepicker.setDefaults( {beforeShow: checkField} );
window.Parsley.addValidator('secondsat', {
validateString: function(value) {
return isCorrectDate(new Date(value));
},
messages: {
en: 'Please use the date picker.'
}
});
$('.myDate input').attr('data-parsley-secondsat','');
});
$("#q10").click(function(){
function isCorrectDate(n) {
var t = n.getDay();
var d = n.getDate();
var m = n.getMonth();
var y = n.getYear();
var lastDay = new Date(y, m + 1, 0);
//console.log(lastDay.getDate());
return (d==15 || d==lastDay.getDate());
}
function checkDate(n) {
return[isCorrectDate(n),""];
}
function checkField(input, inst) {
if ($(input).closest('li').hasClass('toDate')) {
$(input).datepicker("option", {beforeShowDay: checkDate});
}
}
$.datepicker.setDefaults( {beforeShow: checkField} );
window.Parsley.addValidator('secondsat', {
validateString: function(value) {
return isCorrectDate(new Date(value));
},
messages: {
en: 'Please use the date picker.'
}
});
$('.toDate input').attr('data-parsley-secondsat','');
});
I found that the above does not allow me to submit the form and will only work if I click on the date picker. If I click on the field the script doesn't seem to work properly.