Moderator |
|
EDIT 2: Ah, ik snap nu wat je bedoelt: je wilt zowel specifieke datums als specifieke dagen in de week uitschakelen. Ik heb het als volgt voor elkaar gekregen. Je zult alleen het datum-formaat even moeten nakijken, ik kon dit niet doen want de jQuery UI website was voor mij onbereikbaar.
<?php
// disable specific days: http://stackoverflow.com/questions/15400775/jquery-ui-datepicker-disable-array-of-dates
// disable weekdays: http://stackoverflow.com/questions/2968414/disable-specific-days-of-the-week-on-jquery-ui-datepicker
$disableWeekDays = array(1); // 1 = mon, 6 = sat, 0 = sun
$disableDays = array('2014-09-30', '2014-10-16');
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html>
<head>
<title>datepicker disable dates</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
</head>
<body>
<div>
<input type="text" name="" id="date" />
</div>
<script type="text/javascript">
//<![CDATA[
$().ready(function() {
$('#date').datepicker({
'minDate': 0,
'beforeShowDay': function(date) {
var show = true;
<?php
// did we disable weekDays?
if (count($disableWeekDays)) {
?>show = show && $.inArray(date.getDay(), <?php echo json_encode($disableWeekDays) ?>) == -1;<?php
}
// did we disable specific days?
if (count($disableDays)) {
?>show = show && $.inArray(jQuery.datepicker.formatDate('yy-mm-dd', date), <?php echo json_encode($disableDays) ?>) == -1;<?php
}
?>
return [show];
}
});
});
//]]>
</script>
</body>
</html>
<?php // disable specific days: http://stackoverflow.com/questions/15400775/jquery-ui-datepicker-disable-array-of-dates // disable weekdays: http://stackoverflow.com/questions/2968414/disable-specific-days-of-the-week-on-jquery-ui-datepicker $disableWeekDays = array(1); // 1 = mon, 6 = sat, 0 = sun $disableDays = array('2014-09-30', '2014-10-16'); header('Content-Type: text/html; charset=UTF-8'); ?> <!DOCTYPE html> <html> <head> <title>datepicker disable dates</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" /> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script> </head> <body> <div> <input type="text" name="" id="date" /> </div> <script type="text/javascript"> //<![CDATA[ $().ready(function() { $('#date').datepicker({ 'minDate': 0, 'beforeShowDay': function(date) { var show = true; <?php // did we disable weekDays? if (count($disableWeekDays)) { ?>show = show && $.inArray(date.getDay(), <?php echo json_encode ($disableWeekDays) ?>) == -1; <?php } // did we disable specific days? if (count($disableDays)) { ?>show = show && $.inArray(jQuery.datepicker.formatDate('yy-mm-dd', date), <?php echo json_encode ($disableDays) ?>) == -1; <?php } ?> return [show]; } }); }); //]]> </script> </body> </html>
EDIT: verplaatst naar JavaScript forum
Heb je al geGoogled op "datepicker disable dates"?
Eerste resultaat.
Nu weet ik niet precies hoe de datapicker werkt, maar de daar gesuggereerde oplossing ziet er wel redelijk ok uit?
Waarschijnlijk wil je zo min mogelijk PHP (hard)coden in je JavaScript. Meestal / idealiter kun je dit beperken tot (in) de initialisatie van een (datepicker)object. Ik zou dat hier ook proberen indien dat mogelijk is. |