我的Laravel应用程序中有一个在线约会表格,其中有一些提交的Select Doctor
和datepicker
。
假设医生A
将于星期六,星期一和星期三在诊所就诊。医生B
将在星期日,星期二和星期四上班。因此,当任何患者从A
字段中选择医生Select Doctor
时,将在datepicker
日历中激活星期六,星期一和星期三的所有日期,而其他日期将被停用。
我已经停用了datepicker
日历的某些选定日期。但是不能在datepicker
中的选定日期禁用日期。
html
<input class="form-control" id="appointment_datepicker" name="appointment_datepicker" type="text" placeholder="Select Date" value="{{ $user->appointment_datepicker or old('appointment_datepicker') }}">
ajax
$.ajax({
url:"{{ url('/filter_available_date') }}",
type: 'GET',
data: {_token :token, branch_id_appointment : branch_id_appointment, doctor_id_appointment : doctor_id_appointment},
success:function(msg){
$('#appointment_datepicker').datepicker('option', 'beforeShowDay', function(date){
var day = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ msg.indexOf(day) == -1 ] //here msg is the Array of selected Dates which are activated in the datepicker calendar
});
}
});
路线
Route::get('/filter_available_date','frontendAppointmentController@filter_available_date');
控制器
public function filter_available_date(Request $request)
{
$branch_id = $request->branch_id_appointment;
$doctor_id = $request->doctor_id_appointment;
$query = DB::table('service_doctors');
$query->select('doctor_id','inactive_dates_in_this_month');
if($branch_id != '0')
$query->where('branch_id','=', $branch_id);
if($doctor_id != NULL)
$query->where('doctor_id','=', $doctor_id);
$result_time = $query->get();
$result = [$result_time[0]->inactive_dates_in_this_month];
$final_result= explode(',',$result[0]);
return $final_result;
}
如何解决此问题?有人帮忙吗?预先感谢。
答案 0 :(得分:2)
乍一看,似乎是日期不匹配的问题。如果使用下面的示例,则可以看到来自API的数据的外观。
var msg = ["2020-05-11"];
$('#appointment_datepicker').datepicker({
beforeShowDay: function(date) {
var day = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [msg.indexOf(day) == -1]
}
});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>
<input class="form-control" id="appointment_datepicker" name="appointment_datepicker" type="text" placeholder="Select Date">
答案 1 :(得分:0)
这里每天都有一个固定电话号码,例如
Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6
因此,一天的Array
天( ex:var arr = [1、2、3]; )从控制器返回,并且该天将在{{1 }}。
只需在Ajax中更改以下代码
Ajax
datepicker
因此,var arr = [1, 2, 3] //these are the array of days numbers return from controller
$('#appointment_datepicker').datepicker('option', 'beforeShowDay', function(date){
var day = date.getDay();
return [(arr.indexOf(day) != -1)];
});
日历中仅Monday
,Tuesday
和Wednesday
处于活动状态。