Tariff UI: fix decimal price input (#27950)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
Michael Geers 2026-03-05 16:33:19 +01:00 • committed by GitHub
parent f24dcd5e11
commit 456f0d6062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -83,7 +83,7 @@
<div class="position-relative flex-grow-1">
<input
:id="id"
v-model="value"
:value="value"
:list="datalistId"
:type="inputType"
:step="step"
@ -98,6 +98,8 @@
"
:autocomplete="masked || datalistId ? 'off' : null"
:disabled="disabled"
@change="onFieldChange"
@input="onFieldInput"
/>
<button
v-if="showClearButton"
@ -346,6 +348,20 @@ export default {
},
},
methods: {
coerceValue(val) {
if (this.inputType === "number") {
return val === "" ? "" : Number(val);
}
return val;
},
onFieldChange(e) {
this.value = this.coerceValue(e.target.value);
},
onFieldInput(e) {
if (!this.useLazyBinding) {
this.value = this.coerceValue(e.target.value);
}
},
getOptionName(value) {
const translationKey = `config.options.${this.property}.${value || "none"}`;
return this.$te(translationKey) ? this.$t(translationKey) : value;