2

嗨,我正在尝试用flatpickr替换datetimepicker ,但我无法处理这种情况。不希望使用 flatpickr 的 Range 插件我希望能够使用 onChange 事件更改实例的 minDate 或 maxDate。不幸的是,我在指南上几乎没有找到有关此段落的信息

 flatpickr('#start_time', {
    locale: 'it',
    enableTime: true,
    plugins: [
      new confirmDate({
        confirmIcon: "<i class='fa fa-check'></i>",
        confirmText: '',
        showAlways: true,
      }),
    ],
    showAlways: false,
    theme: 'airbnb',
    time_24hr: true,
    altInput: true,
    altFormat: 'F j, Y H:i',
    dateFormat: 'Z',
    weekNumbers: true,
    maxDate: $('#end_time').attr('value'),
    onClose: function(selectedDates, dateStr, instance) {
    // Change #end_time minDate
    },
  });

  flatpickr('#end_time', {
    locale: 'it',
    enableTime: true,
    plugins: [
      new confirmDate({
        confirmIcon: "<i class='fa fa-check'></i>",
        confirmText: '',
        showAlways: true,
      }),
    ],
    showAlways: false,
    theme: 'airbnb',
    time_24hr: true,
    altInput: true,
    altFormat: 'F j, Y H:i',
    dateFormat: 'Z',
    weekNumbers: true,
    minDate: $('#start_time').attr('value'),
    onClose: function(selectedDates, dateStr, instance) {
    // Change #start_time maxDate
    },
  });

我试图玩$('#start_time')[0]._flatpickr.config._maxDate但没有成功

谢谢 ;)

4

1 回答 1

5

以这种方式解决

let startpicker = flatpickr('#start_time', {
    locale: 'it',
    enableTime: true,
    plugins: [
      new confirmDate({
        confirmIcon: "<i class='fa fa-check'></i>",
        confirmText: '',
        showAlways: true,
      }),
    ],
    showAlways: false,
    theme: 'airbnb',
    time_24hr: true,
    altInput: true,
    altFormat: 'F j, Y H:i',
    dateFormat: 'Z',
    weekNumbers: true,
    maxDate: $('#end_time').attr('value'),
    onClose: function(selectedDates, dateStr, instance) {
      endpicker.set('minDate', dateStr);
    },
  });

  let endpicker = flatpickr('#end_time', {
    locale: 'it',
    enableTime: true,
    plugins: [
      new confirmDate({
        confirmIcon: "<i class='fa fa-check'></i>",
        confirmText: '',
        showAlways: true,
      }),
    ],
    showAlways: false,
    theme: 'airbnb',
    time_24hr: true,
    altInput: true,
    altFormat: 'F j, Y H:i',
    dateFormat: 'Z',
    weekNumbers: true,
    minDate: $('#start_time').attr('value'),
    onClose: function(selectedDates, dateStr, instance) {
      startpicker.set('maxDate', dateStr);
    },
  });
于 2018-05-22T14:52:22.570 回答