0

I have four textboxes two for date and two for time to set a reminder like: from 27/07/2017 9:00 to 28/07/2017 14:05.

I am using jquery datetimepicker to select date and bootstrap clockpicker(the clock style picker) to select time.

I have already disabled the past dates for second datetimepicker according to first's selected date.

My code for both is:

                //datetimepicker
                $('.datetimepicker1').datetimepicker({
                    format: 'DD/MM/YYYY',
                    minDate: moment(),
                });

                $('.datetimepicker2').datetimepicker({
                    format: 'DD/MM/YYYY',
                });

                //clockpicker
                $('.clockpicker1').clockpicker({
                    placement: 'bottom',
                    align: 'right',
                    autoclose: true,
                    'default': '04:00',
              //any method like afterdone to set $('.clockpicker2') MIN time
                });

                $('.clockpicker2').clockpicker({
                    placement: 'bottom',
                    align: 'right',
                    autoclose: true,
                    //set minimum time for it
                });

Now, the problem is that I want to set second time according to first selected time for the same day.

Example: If date selected for both fields is 28/07/2017 and time selected from first clockpicker is 10:00 then I can only select time past 10AM from second clockpicker not time before that.

In short, want to set minimum value of this clockpicker to 10:00. I read about beforedone and afterdone methods but have no idea how to set MIN value in it.

WebDevBooster
  • 14,674
  • 9
  • 66
  • 70
Preet
  • 984
  • 2
  • 14
  • 34
  • Hi ,you again. I can't understand why you need clockpicker. If you use default datetimepciker format, you can get hh/MM/ss part. maybe you prefer clockpicker style? If so, i will check it for you. – NicoXiang Jul 25 '17 at 03:00
  • Hi, yes i only want this style. Okay thank you.. – Preet Jul 25 '17 at 03:02

2 Answers2

2

Since clockpicker's author didn't expose mindate interface, i can only write the script below by myself. But min datetime won't reflect in the UI( can still select time past 10AM from second clockpicker, but the value won't change). And the question which we can select datetimepicker2 first has not yet been considered.

<script>
  var flag = false;
  $(function () {

    $('#clockpicker1').clockpicker({
      placement: 'bottom',
      align: 'right',
      autoclose: true,
      'default': 'now',
      afterDone: function () {
        $('#clockpicker2').get(0).value = $('#clockpicker1').get(0).value;
        flag = true;
      }
    });


    $('#clockpicker2').clockpicker({
      placement: 'bottom',
      align: 'right',
      autoclose: true,
      afterDone: function () {
        if (flag) {
          if ($('#clockpicker2').get(0).value < $('#clockpicker1').get(0).value) {
            $('#clockpicker2').get(0).value = $('#clockpicker1').get(0).value;
          }
        }
      }
    });
  });
</script>
NicoXiang
  • 429
  • 9
  • 23
1

Try this:

  $("#datetimepicker1").on("dp.change", function (e) {
        $('#datetimepicker2').data("DateTimePicker").minDate(e.date);
    });

    $("#datetimepicker2").on("dp.change", function (e) {
         $('#datetimepicker1').data("DateTimePicker").maxDate(e.date);
    });
PHP Worm...
  • 4,109
  • 1
  • 25
  • 48