diff --git a/gallery/src/pages/components/ha-form.ts b/gallery/src/pages/components/ha-form.ts index 324eb3a58d..c25ff1067f 100644 --- a/gallery/src/pages/components/ha-form.ts +++ b/gallery/src/pages/components/ha-form.ts @@ -50,13 +50,11 @@ const SCHEMAS: { { type: "boolean", name: "bool", - optional: true, default: false, }, { type: "integer", name: "int", - optional: true, default: 10, }, { @@ -67,7 +65,6 @@ const SCHEMAS: { { type: "string", name: "string", - optional: true, default: "Default", }, { @@ -77,7 +74,6 @@ const SCHEMAS: { ["other", "other"], ], name: "select", - optional: true, default: "default", }, { @@ -87,7 +83,6 @@ const SCHEMAS: { other: "Other", }, name: "multi", - optional: true, default: ["default"], }, { @@ -108,7 +103,6 @@ const SCHEMAS: { { type: "integer", name: "int with default", - optional: true, default: 10, }, { @@ -122,7 +116,6 @@ const SCHEMAS: { { type: "integer", name: "int range optional", - optional: true, valueMin: 0, valueMax: 10, }, @@ -148,7 +141,6 @@ const SCHEMAS: { ["other", "Other"], ], name: "select optional", - optional: true, }, { type: "select", @@ -161,7 +153,6 @@ const SCHEMAS: { ["option", "1000"], ], name: "select many otions", - optional: true, default: "default", }, ], @@ -190,7 +181,6 @@ const SCHEMAS: { option: "1000", }, name: "multi many otions", - optional: true, default: ["default"], }, ], @@ -239,11 +229,10 @@ const SCHEMAS: { valueMin: 1, valueMax: 65535, name: "port", - optional: true, default: 80, }, - { type: "string", name: "path", optional: true, default: "/" }, - { type: "boolean", name: "ssl", optional: true, default: false }, + { type: "string", name: "path", default: "/" }, + { type: "boolean", name: "ssl", default: false }, ], }, ]; diff --git a/src/components/ha-form/ha-form-integer.ts b/src/components/ha-form/ha-form-integer.ts index e8ec34f13f..d4d52fec23 100644 --- a/src/components/ha-form/ha-form-integer.ts +++ b/src/components/ha-form/ha-form-integer.ts @@ -45,7 +45,7 @@ export class HaFormInteger extends LitElement implements HaFormElement {
${this.label}
- ${this.schema.optional + ${!this.schema.required ? html`
@@ -100,7 +100,7 @@ export class HaFormInteger extends LitElement implements HaFormElement { return this.data; } - if (this.schema.optional) { + if (!this.schema.required) { return this.schema.valueMin || 0; } diff --git a/src/components/ha-form/ha-form-select.ts b/src/components/ha-form/ha-form-select.ts index 2df5d03242..bbe561ff40 100644 --- a/src/components/ha-form/ha-form-select.ts +++ b/src/components/ha-form/ha-form-select.ts @@ -29,7 +29,7 @@ export class HaFormSelect extends LitElement implements HaFormElement { } protected render(): TemplateResult { - if (!this.schema.optional && this.schema.options!.length < 6) { + if (this.schema.required && this.schema.options!.length < 6) { return html`
${this.label} @@ -59,7 +59,7 @@ export class HaFormSelect extends LitElement implements HaFormElement { @closed=${stopPropagation} @selected=${this._valueChanged} > - ${this.schema.optional + ${!this.schema.required ? html`` : ""} ${this.schema.options!.map( diff --git a/src/components/ha-form/ha-form-string.ts b/src/components/ha-form/ha-form-string.ts index fc787e4e63..22085ab2a5 100644 --- a/src/components/ha-form/ha-form-string.ts +++ b/src/components/ha-form/ha-form-string.ts @@ -89,7 +89,7 @@ export class HaFormString extends LitElement implements HaFormElement { if (this.data === value) { return; } - if (value === "" && this.schema.optional) { + if (value === "" && !this.schema.required) { value = undefined; } fireEvent(this, "value-changed", { diff --git a/src/components/ha-form/types.ts b/src/components/ha-form/types.ts index c52ba0b947..86122bebc1 100644 --- a/src/components/ha-form/types.ts +++ b/src/components/ha-form/types.ts @@ -15,7 +15,6 @@ export interface HaFormBaseSchema { name: string; default?: HaFormData; required?: boolean; - optional?: boolean; description?: { suffix?: string; suggested_value?: HaFormData }; } diff --git a/src/dialogs/config-flow/step-flow-form.ts b/src/dialogs/config-flow/step-flow-form.ts index a1969dc460..3519540633 100644 --- a/src/dialogs/config-flow/step-flow-form.ts +++ b/src/dialogs/config-flow/step-flow-form.ts @@ -103,12 +103,13 @@ class StepFlowForm extends LitElement { const allRequiredInfoFilledIn = stepData === undefined ? // If no data filled in, just check that any field is required - this.step.data_schema.find((field) => !field.optional) === undefined + this.step.data_schema.find((field) => field.required) === undefined : // If data is filled in, make sure all required fields are stepData && this.step.data_schema.every( (field) => - field.optional || !["", undefined].includes(stepData![field.name]) + !field.required || + !["", undefined].includes(stepData![field.name]) ); if (!allRequiredInfoFilledIn) {