You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
function createDateTimePicker(datePicker, checkbox, date){ |
|
$(datePicker).datetimepicker({ |
|
//useCurrent: false, //Important! See issue #1075 |
|
locale: 'en-gb', |
|
format: 'DD-MM-YYYY HH:mm', |
|
keepInvalid: true, |
|
sideBySide: true, |
|
defaultDate: null, |
|
timeZone: moment.tz.guess() |
|
}); |
|
|
|
$(checkbox).change(function() { |
|
updateDateTimePicker(datePicker, checkbox) |
|
}); |
|
|
|
if (!$(checkbox)[0].checked){ |
|
if ($(datePicker)[0].value == ''){ |
|
$(datePicker)[0].value = date.format('DD-MM-YYYY HH:mm'); |
|
} else if (!$('.alert')[0]) { //Don't convert datetime again after error |
|
$(datePicker)[0].value = moment.utc($(datePicker)[0].value, 'DD-MM-YYYY HH:mm').local().format('DD-MM-YYYY HH:mm'); |
|
} |
|
} else { |
|
$(datePicker).data("DateTimePicker").disable(); |
|
}; |
|
} |
|
|
|
function updateDateTimePicker(picker, checkbox){ |
|
if ($(checkbox).prop("checked")) { |
|
$(picker).data("DateTimePicker").disable(); |
|
} |
|
else { |
|
$(picker).data("DateTimePicker").enable(); |
|
if ($(picker)[0].value == ''){ |
|
$(picker)[0].value = moment().format('DD-MM-YYYY HH:mm'); |
|
} |
|
} |
|
}
|
|
|