From d0926226cd87267fbd5e11d83a8f221a5cc7ac13 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 7 Mar 2022 14:33:09 -0700 Subject: [PATCH] Fix set_min() & set_max() for Date --- api/js/etemplate/Et2Date/Et2Date.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/js/etemplate/Et2Date/Et2Date.ts b/api/js/etemplate/Et2Date/Et2Date.ts index 2b715d663f..0553575528 100644 --- a/api/js/etemplate/Et2Date/Et2Date.ts +++ b/api/js/etemplate/Et2Date/Et2Date.ts @@ -435,6 +435,17 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl this.minDate = min; } + set minDate(min : string | Date) + { + if(this._instance) + { + // Handle timezone offset, flatpickr uses local time + let date = new Date(min); + let formatDate = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000); + this._instance.set('minDate', formatDate) + } + } + /** * Set the minimum allowed date * @param {string | Date} max @@ -444,6 +455,17 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl this.maxDate = max; } + set maxDate(max : string | Date) + { + if(this._instance) + { + // Handle timezone offset, flatpickr uses local time + let date = new Date(max); + let formatDate = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000); + this._instance.set('maxDate', formatDate) + } + } + /** * Override from flatpickr * @returns {any}