Добрый день, возникла трудность с
bootstrap datepicker
У меня есть 2
input'a которым присвоен идентификатор, я хочу при вызове
datepicker получить значение
data-stock_id в событии
beforeShowDay, а так же при открытии должна срабатывать загрузка дат, для того чтобы их вычеркнуть
<input type="text" name="book" value="" class="form-control book" data-stock_id="1"/>
<input type="text" name="book" value="" class="form-control book" data-stock_id="2"/>
var array = new Array();
function load_reservation(stock, year = null, month = null, callback){
jQuery.ajax({
method: "POST",
url: "'.Url::to(['site/ajax-load-reservation']).'",
data: { "stock": stock, "year": year, "month": month },
success: function(data) {
if(data.result==1){
callback(data.array);
}
else callback(null);
},
dataType: "json",
async: false
});
}
$(".book").each(function(){
var id = $(this).attr("data-stock_id");
load_reservation(id, null, null, function(result){
array[id] = result;
console.log("Loaded dates for #"+ id +": "+array[id]);
});
});
$(".book").datepicker({
multidate: true,
startDate: "1d",
language: "ru",
format: "yyyy-dd-mm",
datesdisabled: array[1],
onChangeMonthYear: function (year, month, day) {
var id = $(this).attr("data-stock_id");
load_reservation(id, year, month, function(result){
array[id] = result;
console.log("Month changed ("+ month +"), dates for #"+ id +": "+array[id]);
});
},
beforeShowDay: function(date){
var id = $(this).attr("data-stock_id");
//console.log(stock_id);
var res = [date.getDay() == 0 || available(date, id), "" ];
console.log(id+" is "+ res);
return res;
}
});
function available(date,id) {
ymd = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate();
if ($.inArray(ymd, array[id]) != -1) {
return true;
} else {
return false;
}
}
Подскажите, может есть готовое решение или помогите найти ошибку