mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Allow config flow to show error per field (#19522)
This commit is contained in:
parent
86bbff36ea
commit
107f0da88b
@ -154,6 +154,10 @@ class HaAlert extends LitElement {
|
|||||||
.issue-type.success::after {
|
.issue-type.success::after {
|
||||||
background-color: var(--success-color);
|
background-color: var(--success-color);
|
||||||
}
|
}
|
||||||
|
:host ::slotted(ul) {
|
||||||
|
margin: 0;
|
||||||
|
padding-inline-start: 20px;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,10 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public schema!: readonly HaFormSchema[];
|
@property({ attribute: false }) public schema!: readonly HaFormSchema[];
|
||||||
|
|
||||||
@property({ attribute: false }) public error?: Record<string, string>;
|
@property({ attribute: false }) public error?: Record<
|
||||||
|
string,
|
||||||
|
string | string[]
|
||||||
|
>;
|
||||||
|
|
||||||
@property({ attribute: false }) public warning?: Record<string, string>;
|
@property({ attribute: false }) public warning?: Record<string, string>;
|
||||||
|
|
||||||
@ -228,7 +231,20 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
return this.computeHelper ? this.computeHelper(schema) : "";
|
return this.computeHelper ? this.computeHelper(schema) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeError(error, schema: HaFormSchema | readonly HaFormSchema[]) {
|
private _computeError(
|
||||||
|
error: string | string[],
|
||||||
|
schema: HaFormSchema | readonly HaFormSchema[]
|
||||||
|
): string | TemplateResult {
|
||||||
|
if (Array.isArray(error)) {
|
||||||
|
return html`<ul>
|
||||||
|
${error.map(
|
||||||
|
(err) =>
|
||||||
|
html`<li>
|
||||||
|
${this.computeError ? this.computeError(err, schema) : err}
|
||||||
|
</li>`
|
||||||
|
)}
|
||||||
|
</ul>`;
|
||||||
|
}
|
||||||
return this.computeError ? this.computeError(error, schema) : error;
|
return this.computeError ? this.computeError(error, schema) : error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,8 +201,19 @@ class StepFlowForm extends LitElement {
|
|||||||
step,
|
step,
|
||||||
});
|
});
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._errorMsg =
|
if (err && err.body) {
|
||||||
(err && err.body && err.body.message) || "Unknown error occurred";
|
if (err.body.message) {
|
||||||
|
this._errorMsg = err.body.message;
|
||||||
|
}
|
||||||
|
if (err.body.errors) {
|
||||||
|
this.step = { ...this.step, errors: err.body.errors };
|
||||||
|
}
|
||||||
|
if (!err.body.message && !err.body.errors) {
|
||||||
|
this._errorMsg = "Unknown error occurred";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._errorMsg = "Unknown error occurred";
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this._loading = false;
|
this._loading = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user