From ca2dce62abd223b87cefff9f0eb1b6ffdb3210f6 Mon Sep 17 00:00:00 2001 From: Manh Hung Nguyen Date: Thu, 14 Dec 2023 09:50:06 +0700 Subject: [PATCH] Step builder use FormStep type instead --- src/@episerver/forms-sdk/src/form-step/stepBuilder.ts | 4 ++-- .../forms-sdk/src/form-step/stepDependCondition.ts | 10 +++++----- src/@episerver/forms-sdk/src/models/FormContainer.ts | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/@episerver/forms-sdk/src/form-step/stepBuilder.ts b/src/@episerver/forms-sdk/src/form-step/stepBuilder.ts index 452e5f5..5228935 100644 --- a/src/@episerver/forms-sdk/src/form-step/stepBuilder.ts +++ b/src/@episerver/forms-sdk/src/form-step/stepBuilder.ts @@ -20,7 +20,7 @@ export class StepBuilder { let steps: Step[] = []; let elements: FormElementBase[] = []; - let currentStep = { key: newUniqueID() } as FormElementBase; + let currentStep = { key: newUniqueID() } as FormStep; this._form.formElements.forEach((e,i) => { if (this.isFormStep(e)) { @@ -32,7 +32,7 @@ export class StepBuilder { //reset vars elements = []; - currentStep = {...e}; + currentStep = {...(e as FormStep)}; } elements.push(e); diff --git a/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts b/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts index 1e22c54..f60a116 100644 --- a/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts +++ b/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts @@ -27,25 +27,25 @@ export class StepDependCondition { * @returns */ isSatisfied (stepIndex: number): boolean { - let step = this._form.steps[stepIndex]?.formStep as FormStep; + let step = this._form.steps[stepIndex]?.formStep; if (!step) { return false; } - let dependField = step?.properties?.dependField, + let dependField = step.properties.dependField, storedData = this._formStorage.loadFormDataFromStorage().filter(fs => fs.elementKey === dependField?.key)[0], - funcOfDependCondition = ConditionFunctions[step?.properties?.dependCondition]; + funcOfDependCondition = ConditionFunctions[step.properties.dependCondition]; if (!dependField || !funcOfDependCondition || !storedData) { // no input to check, consider it's OK return true; } if(!dependField && isInArray(dependField, this._inactiveElements)){ - return funcOfDependCondition(null, step?.properties?.dependValue); + return funcOfDependCondition(null, step.properties.dependValue); } - return funcOfDependCondition(storedData?.value, step?.properties?.dependValue); + return funcOfDependCondition(storedData?.value, step.properties.dependValue); } /** diff --git a/src/@episerver/forms-sdk/src/models/FormContainer.ts b/src/@episerver/forms-sdk/src/models/FormContainer.ts index c6bdf29..60c8c89 100644 --- a/src/@episerver/forms-sdk/src/models/FormContainer.ts +++ b/src/@episerver/forms-sdk/src/models/FormContainer.ts @@ -1,3 +1,4 @@ +import { FormStep } from "./elements" import { FormElementBase } from "./elements/base/FormElementBase" /** @@ -28,6 +29,6 @@ export interface FormContainerProperties { } export interface Step { - formStep: FormElementBase + formStep: FormStep elements: FormElementBase[] } \ No newline at end of file