设置默认日期air-datepicker

时间:2018-04-11 07:46:41

标签: javascript jquery typescript datepicker

我正在使用air-datepicker inline

我需要设置它的开始日期。

这是脚本以及我如何尝试这样做。

export function load_datepickers_inline():void {
const search_legs_0_datepicker = $("#search_legs_0_datepicker");
const leg_0_datepicker = $("#search_legs_0_datepicker").datepicker({
  language: gon.locale,
  classes: 'inline-picker',
  selectOtherMonths: true,
  showOtherMonths: true,
  changeMonth: true,
  changeYear:true,
  altField: '#search_legs_0_date',
  selectDate: new Date(search_legs_0_datepicker.attr("data-defaultDate")),
  minDate: new Date(search_legs_0_datepicker.attr('data-mindate')),
  maxDate: new Date(search_legs_0_datepicker.attr('data-maxdate')),
  altFormat: 'yy-mm-dd',
  onSelect: (dateText, inst) => {
    const date = new Date(dateText);
    if (!leg_0_datepicker) { return false; }
    leg_1_datepicker.datepicker("option", "minDate", date);
    if ($("#search_legs_0_hotel_date").length > 0) {
      $('#search_legs_0_hotel_date').datepicker().data('datepicker').update('minDate', date);
      $('#search_legs_0_hotel_date').datepicker().data('datepicker').datepicker("setDate", date);
      $('#search_legs_1_hotel_date').datepicker().data('datepicker').update('minDate', date);
    }
  }
})

const search_legs_1_datepicker = $("#search_legs_1_datepicker");
var leg_1_datepicker = $("#search_legs_1_datepicker").datepicker({
  selectOtherMonths: true,
  showOtherMonths: true,
  language: gon.locale,
  changeMonth: true,
  changeYear:true,
  classes: 'inline-picker',
  altField: '#search_legs_1_date',
  selectDate: new Date(search_legs_1_datepicker.attr("data-defaultDate")),
  minDate: new Date(search_legs_1_datepicker.attr('data-mindate')),
  maxDate: new Date(search_legs_1_datepicker.attr('data-maxdate')),
  altFormat: 'yy-mm-dd',
  onSelect: (formattedDate, date, inst) => {
    if ($("#search_legs_1_hotel_date").length > 0) {
      $('#search_legs_0_hotel_date').datepicker().data('datepicker').update('maxDate', date);
      $('#search_legs_1_hotel_date').datepicker().data('datepicker').update('maxDate', date);
      $('#search_legs_1_hotel_date').datepicker().data('datepicker').datepicker("setDate", date);
    }
  }
})

一切正常,但默认日期不会被隐藏。我需要设置吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:-1)

正如您在文档中看到的,selectDate是一个函数,因此您必须以这种方式使用它:

leg_1_datepicker.selectDate(new Date(2018, 3, 11));