Fix initial value of select selector (#17822)

This commit is contained in:
Bram Kragten 2023-09-05 13:29:47 +02:00 committed by GitHub
parent f7f1a0c32d
commit c3c4bb4421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,8 @@ export const computeInitialHaFormData = (
data[field.name] = 0.0; data[field.name] = 0.0;
} else if (field.type === "select") { } else if (field.type === "select") {
if (field.options.length) { if (field.options.length) {
data[field.name] = field.options[0][0]; const val = field.options[0];
data[field.name] = Array.isArray(val) ? val[0] : val;
} }
} else if (field.type === "positive_time_period_dict") { } else if (field.type === "positive_time_period_dict") {
data[field.name] = { data[field.name] = {
@ -61,7 +62,7 @@ export const computeInitialHaFormData = (
} else if ("select" in selector) { } else if ("select" in selector) {
if (selector.select?.options.length) { if (selector.select?.options.length) {
const val = selector.select.options[0]; const val = selector.select.options[0];
data[field.name] = Array.isArray(val) ? val[0] : val; data[field.name] = typeof val === "string" ? val : val.value;
} }
} else if ("duration" in selector) { } else if ("duration" in selector) {
data[field.name] = { data[field.name] = {