jquery - How to launch the beforeShowDay of DatePicker from another function -
i have datepicker following code. have dropdownbox , upon change in dropdown box want launch datepicker beforeshowday function. how can this?
var freedate;
part of code follows:
$("#mydiv").datepicker({ showothermonths: true, selectothermonths: true, dateformat: "yy/mm/dd", onselect: function(datetext, inst) {}, onchangemonthyear: function(year, month, inst) { $.ajax({ contenttype: "application/json; charset=utf-8", datatype: "json", url: '@url.action("listdates", "party")', data: { date: new date(year, month - 1, 1).tostring("yyyy/mm/dd"), userid: userid }, success: function(data) { freedate = eval(data); }, error: function(request, status, error) {} }); }, beforeshowday: function(datetoshow) { var returnresult = new array(); returnresult.push(true); var itemmatched = false; $.each(freedate, function(key, value) { if (new date(parseint(value.substr(6))).compareto(datetoshow) == 0) { itemmatched = true; returnresult.push('timenotfree'); return; } }); if (!itemmatched) returnresult.push(''); returnresult.push(''); return returnresult; } });
$('#mylist').change(function() { userid = $("#userlist > option:selected").attr("value"); // mylist used have freedate , datepicker must shown accordingly. $.ajax({ contenttype: "application/json; charset=utf-8", datatype: "json", url: '@url.action("listdates", "party")', data: { date: new date($("#mydiv").datepicker("getdate").tostring("yyyy/mm/dd")), userid: userid }, success: function(data) { freedate = eval(data); }, error: function(request, status, error) {} }); $("#mydiv").datepicker("setdate", $("#mydiv").datepicker("getdate").tostring("yyyy/mm/dd")); });
beforeshowday
event fired datepicker before day rendered. can use customize how cell containing day displayed, e.g. can turn red indicate blocked dates.
from understand question, can call datapicker.refresh()
method indicate freedate
variable has changed (by ajax response example) , calendar needs rendered again.
edit
i believe code dropdown, seems uses ajax:
$('#mylist').change( ...
in success callback, have:
freedate = eval(data);
this freedate
changes , should call .refresh()
method. note ajax asynchronous default there delay between selecting value , success event callback.
and here how call method on existing datepicker:
. . . freedate = eval(data); $("#mydiv").datepicker("refresh"); . . .
Comments
Post a Comment