Home › Forums › Backend Issues (wp-admin) › Restrict datepicker ending date by starting date › Reply To: Restrict datepicker ending date by starting date
Hi
this is the code that i used:
(function($) {
$(‘#firstdate .acf-date-picker input.hasDatepicker’).live(“change”, function(e) {
var getval = $(this).val();
var dataname = $(“#firstdate”).attr(“data-name”);
if (dataname == “fecha_de_llegada”) {
var makedate = $(this).val().split(“/”);
var date = new Date(makedate[1] + “/” + makedate[0] + “/” + makedate[2]);
date.setDate(date.getDate() + 1);
if (!isNaN(date.getTime())) {
var getnew = date.toLocaleDateString(‘en-GB’);
var getmyd = getnew.split(‘/’);
var gyear = getmyd[2].toString();
var gmonth = getmyd[1].toString();
var gday = getmyd[0].toString();
$(“#seconddate”).find(‘input[type=text]’).val(date.toLocaleDateString(‘en-GB’));
$(“#seconddate”).find(‘input[type=hidden]’).val(gyear+gmonth+gday);
} else {
alert(“Invalid Date”);
}
}
});
})(jQuery);
make sure that you change the ID/classes of you element:
#firstdate, #seconddate
hope it helps
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.