Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for disabled selectors in config flow #22592

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/ha-form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface HaFormBaseSchema {
suffix?: string;
// This value will be set initially when form is loaded
suggested_value?: HaFormData;
// Disable flag is passed here from backend for config flow
disabled?: boolean;
MindFreeze marked this conversation as resolved.
Show resolved Hide resolved
};
context?: Record<string, string>;
}
Expand Down
15 changes: 13 additions & 2 deletions src/dialogs/config-flow/step-flow-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TemplateResult,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
import { fireEvent } from "../../common/dom/fire_event";
import { isNavigationClick } from "../../common/dom/is-navigation-click";
Expand Down Expand Up @@ -46,6 +47,13 @@ class StepFlowForm extends LitElement {
this.removeEventListener("keydown", this._handleKeyDown);
}

private handleDisabledFields = memoizeOne((schema) =>
schema?.map((field) => ({
...field,
...(field?.description?.disabled ? { disabled: true } : {}),
}))
);

protected render(): TemplateResult {
const step = this.step;
const stepData = this._stepDataProcessed;
Expand All @@ -62,7 +70,9 @@ class StepFlowForm extends LitElement {
.data=${stepData}
.disabled=${this._loading}
@value-changed=${this._stepDataChanged}
.schema=${autocompleteLoginFields(step.data_schema)}
.schema=${autocompleteLoginFields(
this.handleDisabledFields(step.data_schema)
)}
.error=${step.errors}
.computeLabel=${this._labelCallback}
.computeHelper=${this._helperCallback}
Expand Down Expand Up @@ -180,8 +190,9 @@ class StepFlowForm extends LitElement {
Object.keys(stepData).forEach((key) => {
const value = stepData[key];
const isEmpty = [undefined, ""].includes(value);
const field = this.step.data_schema?.find((f) => f.name === key);

if (!isEmpty) {
if (!isEmpty && !field?.description?.disabled) {
toSendData[key] = value;
}
});
Expand Down
Loading