diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index a3eaaea6a4..88da99c7af 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -79,6 +79,8 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { @state() private _errors?: string; + @state() private _yamlErrors?: string; + @state() private _entityId?: string; @state() private _mode: "gui" | "yaml" = "gui"; @@ -602,12 +604,14 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { private _yamlChanged(ev: CustomEvent) { ev.stopPropagation(); + this._dirty = true; if (!ev.detail.isValid) { + this._yamlErrors = ev.detail.errorMsg; return; } + this._yamlErrors = undefined; this._config = ev.detail.value; this._errors = undefined; - this._dirty = true; } private async confirmUnsavedChanged(): Promise { @@ -723,7 +727,21 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { history.back(); } - private _switchUiMode() { + private async _switchUiMode() { + if (this._yamlErrors) { + const result = await showConfirmationDialog(this, { + text: html`${this.hass.localize( + "ui.panel.config.automation.editor.switch_ui_yaml_error" + )}

${this._yamlErrors}`, + confirmText: this.hass!.localize("ui.common.continue"), + destructive: true, + dismissText: this.hass!.localize("ui.common.cancel"), + }); + if (!result) { + return; + } + } + this._yamlErrors = undefined; this._mode = "gui"; } @@ -763,6 +781,13 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } private async _saveScript(): Promise { + if (this._yamlErrors) { + showToast(this, { + message: this._yamlErrors, + }); + return; + } + if (!this.scriptId) { const saved = await this._promptScriptAlias(); if (!saved) {