Some fixes

This commit is contained in:
trading_peter 2025-02-06 22:30:13 +01:00
parent b55e71d144
commit f5377e83ad
2 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@tp/tp-date-input", "name": "@tp/tp-date-input",
"version": "1.0.0", "version": "1.1.0",
"description": "", "description": "",
"main": "tp-date-input.js", "main": "tp-date-input.js",
"scripts": { "scripts": {
@ -13,8 +13,8 @@
"author": "trading_peter", "author": "trading_peter",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"date-fns": "^2.28.0", "date-fns": "^2.0.0",
"date-fns-tz": "^1.3.3", "date-fns-tz": "^2.0.0",
"lit": "^2.2.0" "lit": "^3.0.0"
} }
} }

View File

@ -181,7 +181,7 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
super.firstUpdated(); super.firstUpdated();
this.listen(this, 'input', '_autoMoveCursor'); this.listen(this, 'input', '_autoMoveCursor');
const datepicker = this.querySelector('tp-datepicker'); const datepicker = this.querySelector('tp-date-picker');
if (datepicker) { if (datepicker) {
datepicker.addEventListener('value-changed', e => { datepicker.addEventListener('value-changed', e => {
this.value = e.detail; this.value = e.detail;
@ -378,8 +378,9 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
_setClass(idx) { _setClass(idx) {
switch (this._inputAssign[idx]) { switch (this._inputAssign[idx]) {
case 'dd': case 'dd':
return 'day';
case 'MM': case 'MM':
return ''; return 'month';
case 'y': case 'y':
return 'year'; return 'year';
} }
@ -411,6 +412,10 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
} }
} }
if (this._inputAssign.length !== 3) {
console.error(this.tagname + ': Not all date parts where found. Make sure to have MM, dd, and y in your format string.');
}
if (this.value) { if (this.value) {
this._onValueChanged(); this._onValueChanged();
} }
@ -439,7 +444,7 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
this.invalid = false; this.invalid = false;
if (this.value === null || this.value === undefined || this.value === 'Invalid date') { if (this.value === null || this.value === undefined || this.value === 'Invalid date' || this.value === '') {
this.date = null; this.date = null;
this.value = null; this.value = null;
this._input0 = ''; this._input0 = '';