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

@ -322,32 +322,37 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(LitFlatpickr))
shoelace, shoelace,
dateStyles, dateStyles,
css` css`
: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 */
.input-group__container { /* Scroll buttons */
.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;
width: calc(var(--sl-input-height-medium) / 2); width: calc(var(--sl-input-height-medium) / 2);
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);
} }
.et2-date-time__scrollbuttons > *::part(base) { .et2-date-time__scrollbuttons > *::part(base) {
padding: 3px; padding: 3px;
} }
@ -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())
{ {
this.updateComplete.then(() => if(this._inputNode)
{ {
this._inputNode.value = this.format(formatDate, {dateFormat: 'Y-m-d'}); this._inputNode.value = isNaN(date) ? "" : this.format(date, {dateFormat: 'Y-m-dTH:i'});
}); }
else
{
this.updateComplete.then(() =>
{
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

@ -21,16 +21,22 @@ export class Et2DateTime extends Et2Date
return [ return [
...super.styles, ...super.styles,
css` css`
:host([focused]) ::slotted(button), :host(:hover) ::slotted(button) { :host([focused]) ::slotted(button), :host(:hover) ::slotted(button) {
display: inline-block; display: inline-block;
} }
::slotted(.calendar_button) {
border: none; ::slotted([slot='input']) {
background: transparent; flex: 1 1 auto;
margin-left: -20px; min-width: 17ex;
display: none; }
}
`, ::slotted(.calendar_button) {
border: none;
background: transparent;
margin-left: -20px;
display: none;
}
`,
]; ];
} }