mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 19:56:42 +00:00
Support for disabled selectors in config flow (#22592)
* Support for disabled selectors in config flow * rename flag to readonly * rename to read_only * Merge branch 'dev' of https://github.com/home-assistant/frontend into disabled-fields-config-flow * rework for new backend * Fix disabled entity picker * no longer used type * Update src/dialogs/config-flow/step-flow-form.ts Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com> --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
parent
7ffb0f1e3b
commit
113cc118cf
@ -386,6 +386,7 @@ export class HaEntityPicker extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.disabled=${this.disabled}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.allowCustomValue=${this.allowCustomEntity}
|
.allowCustomValue=${this.allowCustomEntity}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
|
@ -2,13 +2,17 @@ import "@material/mwc-button";
|
|||||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { isNavigationClick } from "../../common/dom/is-navigation-click";
|
import { isNavigationClick } from "../../common/dom/is-navigation-click";
|
||||||
import "../../components/ha-alert";
|
import "../../components/ha-alert";
|
||||||
import { computeInitialHaFormData } from "../../components/ha-form/compute-initial-ha-form-data";
|
import { computeInitialHaFormData } from "../../components/ha-form/compute-initial-ha-form-data";
|
||||||
import "../../components/ha-form/ha-form";
|
import "../../components/ha-form/ha-form";
|
||||||
import type { HaFormSchema } from "../../components/ha-form/types";
|
import type {
|
||||||
|
HaFormSchema,
|
||||||
|
HaFormSelector,
|
||||||
|
} from "../../components/ha-form/types";
|
||||||
import "../../components/ha-markdown";
|
import "../../components/ha-markdown";
|
||||||
import "../../components/ha-spinner";
|
import "../../components/ha-spinner";
|
||||||
import { autocompleteLoginFields } from "../../data/auth";
|
import { autocompleteLoginFields } from "../../data/auth";
|
||||||
@ -38,6 +42,15 @@ class StepFlowForm extends LitElement {
|
|||||||
this.removeEventListener("keydown", this._handleKeyDown);
|
this.removeEventListener("keydown", this._handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleReadOnlyFields = memoizeOne((schema) =>
|
||||||
|
schema?.map((field) => ({
|
||||||
|
...field,
|
||||||
|
...(Object.values((field as HaFormSelector)?.selector ?? {})[0]?.read_only
|
||||||
|
? { disabled: true }
|
||||||
|
: {}),
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const step = this.step;
|
const step = this.step;
|
||||||
const stepData = this._stepDataProcessed;
|
const stepData = this._stepDataProcessed;
|
||||||
@ -53,7 +66,9 @@ class StepFlowForm extends LitElement {
|
|||||||
.data=${stepData}
|
.data=${stepData}
|
||||||
.disabled=${this._loading}
|
.disabled=${this._loading}
|
||||||
@value-changed=${this._stepDataChanged}
|
@value-changed=${this._stepDataChanged}
|
||||||
.schema=${autocompleteLoginFields(step.data_schema)}
|
.schema=${autocompleteLoginFields(
|
||||||
|
this.handleReadOnlyFields(step.data_schema)
|
||||||
|
)}
|
||||||
.error=${step.errors}
|
.error=${step.errors}
|
||||||
.computeLabel=${this._labelCallback}
|
.computeLabel=${this._labelCallback}
|
||||||
.computeHelper=${this._helperCallback}
|
.computeHelper=${this._helperCallback}
|
||||||
@ -178,8 +193,10 @@ class StepFlowForm extends LitElement {
|
|||||||
Object.keys(stepData).forEach((key) => {
|
Object.keys(stepData).forEach((key) => {
|
||||||
const value = stepData[key];
|
const value = stepData[key];
|
||||||
const isEmpty = [undefined, ""].includes(value);
|
const isEmpty = [undefined, ""].includes(value);
|
||||||
|
const field = this.step.data_schema?.find((f) => f.name === key);
|
||||||
if (!isEmpty) {
|
const selector = (field as HaFormSelector)?.selector ?? {};
|
||||||
|
const read_only = (Object.values(selector)[0] as any)?.read_only;
|
||||||
|
if (!isEmpty && !read_only) {
|
||||||
toSendData[key] = value;
|
toSendData[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user