From 23ee95e45f851570f87f509d00c1f5a46071967b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 22 Jun 2021 11:22:19 +0200 Subject: [PATCH] js: Only show a single datetime picker in each container at a time --- public/js/icinga/behavior/datetime-picker.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/public/js/icinga/behavior/datetime-picker.js b/public/js/icinga/behavior/datetime-picker.js index 0a28004f9..36b9887af 100644 --- a/public/js/icinga/behavior/datetime-picker.js +++ b/public/js/icinga/behavior/datetime-picker.js @@ -87,6 +87,9 @@ return format === this.dateFormat ? Flatpickr.formatDate(date, format, locale) : dateTimeFormatter.format(date); + }, + onOpen: function (selectedDates, dateStr, instance) { + _this.closePickers(instance); } }; @@ -135,6 +138,20 @@ }, this); }; + /** + * Close all other flatpickr instances and keep the given one + * + * @param fp {Flatpickr} + */ + DatetimePicker.prototype.closePickers = function (fp) { + var containerId = this._pickers.get(fp); + this._pickers.forEach(function (cId, fp2) { + if (cId === containerId && fp2 !== fp) { + fp2.close(); + } + }, this); + }; + DatetimePicker.prototype.createFormatter = function (withDate, withTime) { var options = {}; if (withDate) {