Et2Date fixes

- Fix mobile get / set value was not actually setting value properly
- Set a minimum input width
This commit is contained in:
nathan 2023-02-24 11:58:16 -07:00
parent ae01e30d55
commit 206652307b
2 changed files with 48 additions and 30 deletions

View File

@ -325,18 +325,22 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr))
:host { :host {
width: auto; width: auto;
} }
::slotted([slot='input'])
{ ::slotted([slot='input']) {
flex: 1 1 auto; flex: 1 1 auto;
min-width: 12ex;
} }
/* Scroll buttons */ /* Scroll buttons */
.input-group__container { .input-group__container {
position: relative; position: relative;
} }
.input-group__container:hover .et2-date-time__scrollbuttons { .input-group__container:hover .et2-date-time__scrollbuttons {
display: flex; display: flex;
} }
.et2-date-time__scrollbuttons { .et2-date-time__scrollbuttons {
display: none; display: none;
flex-direction: column; flex-direction: column;
@ -344,6 +348,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr))
position: absolute; position: absolute;
right: 0px; right: 0px;
} }
.et2-date-time__scrollbuttons > * { .et2-date-time__scrollbuttons > * {
font-size: var(--sl-font-size-2x-small); font-size: var(--sl-font-size-2x-small);
height: calc(var(--sl-input-height-medium) / 2); height: calc(var(--sl-input-height-medium) / 2);
@ -621,16 +626,23 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr))
{ {
date = new Date(value); date = new Date(value);
} }
// Handle timezone offset, flatpickr uses local time
let formatDate = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000);
if(typeof egwIsMobile == "function" && egwIsMobile()) if(typeof egwIsMobile == "function" && egwIsMobile())
{
if(this._inputNode)
{
this._inputNode.value = isNaN(date) ? "" : this.format(date, {dateFormat: 'Y-m-dTH:i'});
}
else
{ {
this.updateComplete.then(() => this.updateComplete.then(() =>
{ {
this._inputNode.value = this.format(formatDate, {dateFormat: 'Y-m-d'}); this._inputNode.value = isNaN(date) ? "" : this.format(date, {dateFormat: 'Y-m-dTH:i'});
}); });
}
return; return;
} }
// Handle timezone offset, flatpickr uses local time
let formatDate = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000);
if(!this._instance) if(!this._instance)
{ {
this.defaultDate = formatDate; this.defaultDate = formatDate;
@ -651,7 +663,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr))
{ {
return flatpickr.formatDate(<Date>this.defaultDate, this.getOptions().dateFormat); return flatpickr.formatDate(<Date>this.defaultDate, this.getOptions().dateFormat);
} }
return this._inputNode?.value || ''; return this._inputNode?.value + "Z" || '';
} }
let value = this._inputElement.value; let value = this._inputElement.value;

View File

@ -24,6 +24,12 @@ export class Et2DateTime extends Et2Date
:host([focused]) ::slotted(button), :host(:hover) ::slotted(button) { :host([focused]) ::slotted(button), :host(:hover) ::slotted(button) {
display: inline-block; display: inline-block;
} }
::slotted([slot='input']) {
flex: 1 1 auto;
min-width: 17ex;
}
::slotted(.calendar_button) { ::slotted(.calendar_button) {
border: none; border: none;
background: transparent; background: transparent;