Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 2 additions & 13 deletions gallery/src/pages/components/ha-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ const SCHEMAS: {
{
type: "boolean",
name: "bool",
optional: true,
default: false,
},
{
type: "integer",
name: "int",
optional: true,
default: 10,
},
{
Expand All @@ -67,7 +65,6 @@ const SCHEMAS: {
{
type: "string",
name: "string",
optional: true,
default: "Default",
},
{
Expand All @@ -77,7 +74,6 @@ const SCHEMAS: {
["other", "other"],
],
name: "select",
optional: true,
default: "default",
},
{
Expand All @@ -87,7 +83,6 @@ const SCHEMAS: {
other: "Other",
},
name: "multi",
optional: true,
default: ["default"],
},
{
Expand All @@ -108,7 +103,6 @@ const SCHEMAS: {
{
type: "integer",
name: "int with default",
optional: true,
default: 10,
},
{
Expand All @@ -122,7 +116,6 @@ const SCHEMAS: {
{
type: "integer",
name: "int range optional",
optional: true,
valueMin: 0,
valueMax: 10,
},
Expand All @@ -148,7 +141,6 @@ const SCHEMAS: {
["other", "Other"],
],
name: "select optional",
optional: true,
},
{
type: "select",
Expand All @@ -161,7 +153,6 @@ const SCHEMAS: {
["option", "1000"],
],
name: "select many otions",
optional: true,
default: "default",
},
],
Expand Down Expand Up @@ -190,7 +181,6 @@ const SCHEMAS: {
option: "1000",
},
name: "multi many otions",
optional: true,
default: ["default"],
},
],
Expand Down Expand Up @@ -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 },
],
},
];
Expand Down
6 changes: 3 additions & 3 deletions src/components/ha-form/ha-form-integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class HaFormInteger extends LitElement implements HaFormElement {
<div>
${this.label}
<div class="flex">
${this.schema.optional
${!this.schema.required
? html`
<ha-checkbox
@change=${this._handleCheckboxChange}
Expand All @@ -61,7 +61,7 @@ export class HaFormInteger extends LitElement implements HaFormElement {
.min=${this.schema.valueMin}
.max=${this.schema.valueMax}
.disabled=${this.disabled ||
(this.data === undefined && this.schema.optional)}
(this.data === undefined && !this.schema.required)}
@change=${this._valueChanged}
></ha-slider>
</div>
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/ha-form/ha-form-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<div>
${this.label}
Expand Down Expand Up @@ -59,7 +59,7 @@ export class HaFormSelect extends LitElement implements HaFormElement {
@closed=${stopPropagation}
@selected=${this._valueChanged}
>
${this.schema.optional
${!this.schema.required
? html`<mwc-list-item value=""></mwc-list-item>`
: ""}
${this.schema.options!.map(
Expand Down
2 changes: 1 addition & 1 deletion src/components/ha-form/ha-form-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface HaFormBaseSchema {
name: string;
default?: HaFormData;
required?: boolean;
optional?: boolean;
description?: { suffix?: string; suggested_value?: HaFormData };
}

Expand Down
5 changes: 3 additions & 2 deletions src/dialogs/config-flow/step-flow-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down