mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Handle falsy value in ha-yaml-editor (object selector) (#22142)
* Handle falsy value in ha-yaml-editor (object selector) * handle explicit `null`
This commit is contained in:
parent
4e96ad5f28
commit
e92be566a0
@ -805,7 +805,8 @@ export class HaServiceControl extends LitElement {
|
|||||||
const value = ev.detail.value;
|
const value = ev.detail.value;
|
||||||
if (
|
if (
|
||||||
this._value?.data?.[key] === value ||
|
this._value?.data?.[key] === value ||
|
||||||
(!this._value?.data?.[key] && (value === "" || value === undefined))
|
((!this._value?.data || !(key in this._value.data)) &&
|
||||||
|
(value === "" || value === undefined))
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import type { HaCodeEditor } from "./ha-code-editor";
|
|||||||
import "./ha-button";
|
import "./ha-button";
|
||||||
|
|
||||||
const isEmpty = (obj: Record<string, unknown>): boolean => {
|
const isEmpty = (obj: Record<string, unknown>): boolean => {
|
||||||
if (typeof obj !== "object") {
|
if (typeof obj !== "object" || obj === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
@ -59,14 +59,13 @@ export class HaYamlEditor extends LitElement {
|
|||||||
|
|
||||||
public setValue(value): void {
|
public setValue(value): void {
|
||||||
try {
|
try {
|
||||||
this._yaml =
|
this._yaml = !isEmpty(value)
|
||||||
value && !isEmpty(value)
|
? dump(value, {
|
||||||
? dump(value, {
|
schema: this.yamlSchema,
|
||||||
schema: this.yamlSchema,
|
quotingType: '"',
|
||||||
quotingType: '"',
|
noRefs: true,
|
||||||
noRefs: true,
|
})
|
||||||
})
|
: "";
|
||||||
: "";
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(err, value);
|
console.error(err, value);
|
||||||
@ -75,7 +74,7 @@ export class HaYamlEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(): void {
|
protected firstUpdated(): void {
|
||||||
if (this.defaultValue) {
|
if (this.defaultValue !== undefined) {
|
||||||
this.setValue(this.defaultValue);
|
this.setValue(this.defaultValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user