From 38b507dcd1bff4f653e93ce270f71c508afe32d1 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 17 Jan 2023 10:52:02 -0700 Subject: [PATCH] Et2Date: Stop required validation showing on initial load even with a value --- api/js/etemplate/Et2Date/Et2Date.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api/js/etemplate/Et2Date/Et2Date.ts b/api/js/etemplate/Et2Date/Et2Date.ts index 2cb097dc72..82ab4cc823 100644 --- a/api/js/etemplate/Et2Date/Et2Date.ts +++ b/api/js/etemplate/Et2Date/Et2Date.ts @@ -246,7 +246,9 @@ export function formatDate(date : Date, options = {dateFormat: ""}) : string let replace_map = { d: (date.getUTCDate() < 10 ? "0" : "") + date.getUTCDate(), m: (date.getUTCMonth() < 9 ? "0" : "") + (date.getUTCMonth() + 1), - Y: "" + date.getUTCFullYear() + Y: "" + date.getUTCFullYear(), + H: ("0" + date.getUTCHours()).slice(-2), + i: ("0" + date.getUTCMinutes()).slice(-2) } if(dateformat.indexOf("M") != -1) { @@ -460,6 +462,10 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr)) { this.findInputField().setAttribute("data-input", ""); } + if(this.defaultDate) + { + this._inputNode.value = flatpickr.formatDate(this.defaultDate, this.getOptions().dateFormat); + } } this.initializeComponent(); @@ -618,12 +624,18 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr)) { this.setDate(formatDate); } + + this.requestUpdate("value", this._oldValue); } get value() { if(!this._inputElement) { + if(this.defaultDate) + { + return flatpickr.formatDate(this.defaultDate, this.getOptions().dateFormat); + } return this._inputNode?.value || ''; } let value = this._inputElement.value;