Allow to input decimal in ha-form-float (#10575)

This commit is contained in:
Bram Kragten 2021-11-08 18:28:17 +01:00 committed by GitHub
parent 0e8a06e24d
commit 67d79d618a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -47,12 +47,19 @@ export class HaFormFloat extends LitElement implements HaFormElement {
private _valueChanged(ev: Event) { private _valueChanged(ev: Event) {
const source = ev.target as TextField; const source = ev.target as TextField;
const rawValue = source.value; const rawValue = source.value.replace(",", ".");
let value: number | undefined; let value: number | undefined;
if (rawValue.endsWith(".")) {
return;
}
if (rawValue !== "") { if (rawValue !== "") {
value = parseFloat(rawValue); value = parseFloat(rawValue);
if (isNaN(value)) {
value = undefined;
}
} }
// Detect anything changed // Detect anything changed
@ -61,7 +68,6 @@ export class HaFormFloat extends LitElement implements HaFormElement {
const newRawValue = value === undefined ? "" : String(value); const newRawValue = value === undefined ? "" : String(value);
if (source.value !== newRawValue) { if (source.value !== newRawValue) {
source.value = newRawValue; source.value = newRawValue;
return;
} }
return; return;
} }

View File

@ -241,7 +241,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
); );
const lastDate = this._lastLogbookDate || hoursToShowDate; const lastDate = this._lastLogbookDate || hoursToShowDate;
const now = new Date(); const now = new Date();
let newEntries; let newEntries: LogbookEntry[];
try { try {
[newEntries] = await Promise.all([ [newEntries] = await Promise.all([
@ -256,6 +256,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
]); ]);
} catch (err: any) { } catch (err: any) {
this._error = err.message; this._error = err.message;
return;
} }
const logbookEntries = this._logbookEntries const logbookEntries = this._logbookEntries