Move valid so we don't cache an empty element for add-on config (#7394)

This commit is contained in:
Joakim Sørensen 2020-10-19 15:23:13 +02:00 committed by GitHub
parent a4ea4b1f5f
commit 7c51001c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,13 +39,11 @@ class HassioAddonConfig extends LitElement {
@property({ type: Boolean }) private _configHasChanged = false; @property({ type: Boolean }) private _configHasChanged = false;
@property({ type: Boolean }) private _valid = true;
@query("ha-yaml-editor", true) private _editor!: HaYamlEditor; @query("ha-yaml-editor", true) private _editor!: HaYamlEditor;
protected render(): TemplateResult { protected render(): TemplateResult {
const editor = this._editor;
// If editor not rendered, don't show the error.
const valid = editor ? editor.isValid : true;
return html` return html`
<h1>${this.addon.name}</h1> <h1>${this.addon.name}</h1>
<ha-card header="Configuration"> <ha-card header="Configuration">
@ -54,7 +52,7 @@ class HassioAddonConfig extends LitElement {
@value-changed=${this._configChanged} @value-changed=${this._configChanged}
></ha-yaml-editor> ></ha-yaml-editor>
${this._error ? html` <div class="errors">${this._error}</div> ` : ""} ${this._error ? html` <div class="errors">${this._error}</div> ` : ""}
${valid ? "" : html` <div class="errors">Invalid YAML</div> `} ${this._valid ? "" : html` <div class="errors">Invalid YAML</div> `}
</div> </div>
<div class="card-actions"> <div class="card-actions">
<ha-progress-button class="warning" @click=${this._resetTapped}> <ha-progress-button class="warning" @click=${this._resetTapped}>
@ -62,7 +60,7 @@ class HassioAddonConfig extends LitElement {
</ha-progress-button> </ha-progress-button>
<ha-progress-button <ha-progress-button
@click=${this._saveTapped} @click=${this._saveTapped}
.disabled=${!this._configHasChanged || !valid} .disabled=${!this._configHasChanged || !this._valid}
> >
Save Save
</ha-progress-button> </ha-progress-button>
@ -78,9 +76,9 @@ class HassioAddonConfig extends LitElement {
} }
} }
private _configChanged(): void { private _configChanged(ev): void {
this._configHasChanged = true; this._configHasChanged = true;
this.requestUpdate(); this._valid = ev.detail.isValid;
} }
private async _resetTapped(ev: CustomEvent): Promise<void> { private async _resetTapped(ev: CustomEvent): Promise<void> {