Process expandable initial data also for none required expandables (#24733)

* Process expandable initial data also for none required expandables

* Update compute-initial-ha-form-data.ts

* check required fields of sections too when submitting
This commit is contained in:
Bram Kragten
2025-03-24 16:31:06 +01:00
committed by GitHub
parent 586a137037
commit bbe549fa86
2 changed files with 19 additions and 8 deletions

View File

@@ -144,17 +144,24 @@ class StepFlowForm extends LitElement {
private async _submitStep(): Promise<void> {
const stepData = this._stepData || {};
const checkAllRequiredFields = (
schema: readonly HaFormSchema[],
data: Record<string, any>
) =>
schema.every(
(field) =>
(!field.required || !["", undefined].includes(data[field.name])) &&
(field.type !== "expandable" ||
(!field.required && data[field.name] === undefined) ||
checkAllRequiredFields(field.schema, data[field.name]))
);
const allRequiredInfoFilledIn =
stepData === undefined
? // If no data filled in, just check that any field is required
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.required ||
!["", undefined].includes(stepData![field.name])
);
checkAllRequiredFields(this.step.data_schema, stepData);
if (!allRequiredInfoFilledIn) {
this._errorMsg = this.hass.localize(