js: Only show a single datetime picker in each container at a time

This commit is contained in:
Johannes Meyer 2021-06-22 11:22:19 +02:00
parent b75cf362b8
commit 23ee95e45f
1 changed files with 17 additions and 0 deletions

View File

@ -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) {