我的 Laravel 应用程序中有一个在线预约表格,其中包含一些已归档的 Select Doctor
和 datepicker
。
假设医生 A
将于周六、周一和周三到诊所。 B
医生将于周日、周二、周四有空。因此,当任何患者从选择医生
字段中选择医生A
时,所有周六、周一和周三的日期都将在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');
Controller
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;
}
如何解决这个问题?有人帮忙吗?提前致谢。
最佳答案
乍一看,这似乎是日期不匹配的问题。如果您使用下面的示例,您可以看到来自 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">
关于php - 禁用日期选择器中选定日期的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61700604/