mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Remove optional field from ha-form schema type (#11538)
This commit is contained in:
parent
890ad9a1c8
commit
deba6a0db4
@ -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 },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
@ -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}
|
||||
@ -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>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
@ -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(
|
||||
|
@ -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", {
|
||||
|
@ -15,7 +15,6 @@ export interface HaFormBaseSchema {
|
||||
name: string;
|
||||
default?: HaFormData;
|
||||
required?: boolean;
|
||||
optional?: boolean;
|
||||
description?: { suffix?: string; suggested_value?: HaFormData };
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user