Skip to content

Commit

Permalink
Step builder use FormStep type instead
Browse files Browse the repository at this point in the history
  • Loading branch information
hungoptimizely committed Dec 14, 2023
1 parent a50054c commit ca2dce6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/@episerver/forms-sdk/src/form-step/stepBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -32,7 +32,7 @@ export class StepBuilder {

//reset vars
elements = [];
currentStep = {...e};
currentStep = {...(e as FormStep)};
}

elements.push(e);
Expand Down
10 changes: 5 additions & 5 deletions src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/@episerver/forms-sdk/src/models/FormContainer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FormStep } from "./elements"
import { FormElementBase } from "./elements/base/FormElementBase"

/**
Expand Down Expand Up @@ -28,6 +29,6 @@ export interface FormContainerProperties {
}

export interface Step {
formStep: FormElementBase
formStep: FormStep
elements: FormElementBase[]
}

0 comments on commit ca2dce6

Please sign in to comment.