How to get attribute of the input in bootstrap datepicker beforeShowDay event?

Good day, there was a problem with bootstrap datepicker
I have 2 input'a which has the ID I want when calling the datepicker to the value of the data-stock_id in the event beforeShowDayand when opened can trigger the download of the dates, in order for them to strike

<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("dates Loaded for #"+ id +": "+array[id]);
 }); 
});

$(".book").datepicker({

 multidate: true,
 startDate: "1d",
 language: "EN",
 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("changed Month ("+ 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;
}
 }


Tell me, is there a ready solution or help to find the error
July 8th 19 at 11:17

Find more questions by tags JavaScriptjQuery