javascript - Disable specific datepicker days -
i doing dating system in php , have set datepicker disable days had maximum number of appointments. in order perform process, applied following:
<script> function ndates(date){ var nfechas = false; $.ajax({ type: "post", url: 'prueba.php', data: {date}, async: false, success: function(data) { if (data == 1) nfechas = true; else nfechas = false; }, error: function() { alert('error occured'); } }); return nfechas; } $( function() { $.datepicker.setdefaults($.datepicker.regional["es"]); $( "#datepicker" ).datepicker({ dateformat: 'yy-mm-dd', changemonth:true, changeyear:true, yearrange: "2017:2018", firstday: 1, mindate: 0, beforeshowday: function (date) { var dateslimits = 20; var day = date.getday(); var dd = date.getdate(); var mm = date.getmonth()+1; var yyyy = date.getfullyear(); if(dd<10){ dd='0'+dd; } if(mm<10){ mm='0'+mm; } var date = yyyy+'-'+mm+'-'+dd; if (day == 6 || day == 0 ) { return [false, "somecssclass"] } else { if (ndates(date)){ return [true, "someothercssclass"] } else { return [false, "somecssclass"] } }}, monthnames: ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'], monthnamesshort: ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'], daynamesmin: ['dom', 'lun', 'mar', 'mie', 'jue', 'vie', 'sab'], closetext: 'cerrar', prevtext: 'anterior', nexttext: 'siguiente', currenttext: 'hoy', }); }); </script> what want disable specific days, example (14-09-2017) (25-12-2017) (28-12-2017) , on, maintaining have done far. have read little , applied things, can not find way adapt have read.
you should fetch dates wish disable before instanciating datepicker.
as now, trigger 30 different ajax requests (one each day, calendar renders).
and once request out fetch result, script dosn't "wait" it.
line return nfechas; occurs immediately.
ajax assynchronous... takes couple milliseconds send request , come result. asynchronous means : doesn't "pause" script.
and if pausing script... take 10 seconds (maybe more) render calendar, i'm sure not like.
it way more "expensive" on requests if dates disabled in array on page load. on calendar render, check if date in array disable or not.
so best solution here.
edit
try this:
if (day == 6 || day == 0 ) { return [false, "somecssclass"] } else if (disabledarray.indexof(date) != -1){ return [false, "someothercssclass"] } else { return [true, "anothercssclass"] }
Comments
Post a Comment