datetimepicker icon indicating copy to clipboard operation
datetimepicker copied to clipboard

Set options runtime DateTimePicker

Open HarshalSharma21 opened this issue 6 years ago • 1 comments

Hi, It's a great plugin. Thanks to developers. I am facing an issue to set minTime on run time we want to set minimum date time to current date & time for today it should not pick the time less than a current while for tomorrow or any future dates it should pick any time. For this, I tried "Set options runtime DateTimePicker" but it is not working? Even it is not working in the example given on demo URL https://xdsoft.net/jqplugins/datetimepicker/ date time

Let me know if it's possible to resolve? Thanks

HarshalSharma21 avatar Feb 20 '19 06:02 HarshalSharma21

This works for me: Note: I use MomentJS for date manipulations.

var minDate = moment(new Date());
var $datetimepicker = $('input.datetimepicker');
$datetimepicker.datetimepicker({
      formatTime:'h:i a',
      format: 'd/m/Y h:i a',
      step: 15,
      inline: false,
      validateOnBlur: false,
      lang:'en',
      defaultTime: minTime,
      minDate: minDate._i,
      minTime: minTime,
      onSelectDate: function(selectedTime, $input){
        var selectedDate = $input.datetimepicker('getValue');
        if (minDate.format('DMY') === moment(selectedDate).format('DMY')){
          this.setOptions({
            minTime: minDate.format('HH:mm')
          })
        } else {
          this.setOptions({
            minTime: '00:00'
          })
        }
      }
    });

prcongithub avatar Sep 11 '19 05:09 prcongithub