mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Fix Duration Selector Default (#12098)
* Fix Duration Default * USe initial form data function
This commit is contained in:
parent
840858b18c
commit
2d9b50defc
@ -1,4 +1,5 @@
|
|||||||
import { HaFormSchema } from "./types";
|
import type { Selector } from "../../data/selector";
|
||||||
|
import type { HaFormSchema } from "./types";
|
||||||
|
|
||||||
export const computeInitialHaFormData = (
|
export const computeInitialHaFormData = (
|
||||||
schema: HaFormSchema[]
|
schema: HaFormSchema[]
|
||||||
@ -31,6 +32,25 @@ export const computeInitialHaFormData = (
|
|||||||
minutes: 0,
|
minutes: 0,
|
||||||
seconds: 0,
|
seconds: 0,
|
||||||
};
|
};
|
||||||
|
} else if ("selector" in field) {
|
||||||
|
const selector: Selector = field.selector;
|
||||||
|
if ("boolean" in selector) {
|
||||||
|
data[field.name] = false;
|
||||||
|
} else if ("text" in selector) {
|
||||||
|
data[field.name] = "";
|
||||||
|
} else if ("number" in selector) {
|
||||||
|
data[field.name] = "min" in selector.number ? selector.number.min : 0;
|
||||||
|
} else if ("select" in selector) {
|
||||||
|
if (selector.select.options.length) {
|
||||||
|
data[field.name] = selector.select.options[0][0];
|
||||||
|
}
|
||||||
|
} else if ("duration" in selector) {
|
||||||
|
data[field.name] = {
|
||||||
|
hours: 0,
|
||||||
|
minutes: 0,
|
||||||
|
seconds: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import "../ha-duration-input";
|
|
||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { DurationSelector } from "../../data/selector";
|
import type { DurationSelector } from "../../data/selector";
|
||||||
import { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import "../ha-duration-input";
|
||||||
|
|
||||||
@customElement("ha-selector-duration")
|
@customElement("ha-selector-duration")
|
||||||
export class HaTimeDuration extends LitElement {
|
export class HaTimeDuration extends LitElement {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user