php - 禁用日期选择器中选定日期的日期

标签 php jquery laravel laravel-5 datepicker

我的 Laravel 应用程序中有一个在线预约表格,其中包含一些已归档的 Select Doctordatepicker

假设医生 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;
}

日历 enter image description here

如何解决这个问题?有人帮忙吗?提前致谢。

最佳答案

乍一看,这似乎是日期不匹配的问题。如果您使用下面的示例,您可以看到来自 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/

相关文章:

php - 使用 cURL 登录,然后使用 cURL 发出另一个请求

php - 我如何告诉 Apache2,默认运行 mod_php5,但在 CGI 模式下运行此 VH?

php - Zend_Http_Client cURL 授权示例

javascript - 如何在javascript中读取txt文件的最后一个值

javascript - 如何使用 jQuery 可编辑插件检查 ajax 是否成功完成

javascript - jQuery 将数据发布到 servlet

php - 如何清除 jquery 中幻灯片上的表单值?

php - 使用 laravel 5 和 Auth 更新登录用户帐户设置

javascript - 配置文件脚本未正确显示

php - Laravel 一次修改多行