Skip to content

Commit 6df150c

Browse files
Merge pull request #164 from episerver/master
Merger Master to Develop
2 parents 6a4a34f + 8026c7b commit 6df150c

File tree

11 files changed

+23
-16
lines changed

11 files changed

+23
-16
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "content-headless-form-js-sdk",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Workspace root",
55
"workspaces": [
66
"src/@episerver/forms-react",

src/@episerver/forms-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@episerver/forms-react",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Forms react components render a form from JSON data",
55
"author": "Optimizely",
66
"license": "ISC",

src/@episerver/forms-react/src/components/FormBody.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React, { useEffect, useRef } from "react";
22
import { useForms } from "../context/store";
33
import { StepHelper, FormContainer, FormSubmitter, IdentityInfo, isInArray, isNull,
44
isNullOrEmpty, FormSubmitModel, FormSubmitResult, SubmitButton, FormCache,
5-
FormConstants, ProblemDetail, StepDependCondition, getConfirmationData } from "@episerver/forms-sdk";
5+
FormConstants, ProblemDetail, StepDependCondition, getConfirmationData,
6+
SatisfiedActionType} from "@episerver/forms-sdk";
67
import { RenderElementInStep } from "./RenderElementInStep";
78
import { DispatchFunctions } from "../context/dispatchFunctions";
89
import { FormStepNavigation } from "./FormStepNavigation";
@@ -102,7 +103,10 @@ export const FormBody = (props: FormBodyProps) => {
102103

103104
//get inactives element
104105
let inactives = (formContext?.elementDependencies ?? [])
105-
.filter(dependency => !dependency.isSatisfied)
106+
.filter(dependency =>
107+
(!dependency.isSatisfied && dependency.sastisfiedAction === SatisfiedActionType.Show)
108+
|| (dependency.isSatisfied && dependency.sastisfiedAction === SatisfiedActionType.Hide)
109+
)
106110
.map(dependency => dependency.elementKey);
107111

108112
//filter submissions by active elements and current step

src/@episerver/forms-react/src/context/dispatchFunctions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ export class DispatchFunctions {
1616
});
1717
}
1818

19-
UpdateElementDependencies = (elementKey: string, condition: boolean) => {
19+
UpdateElementDependencies = (elementKey: string, condition: boolean, satisfiedAction: string) => {
2020
this._dispatch({
2121
type: ActionType.UpdateElementDependencies,
2222
elementKey: elementKey,
23-
condition
23+
condition,
24+
satisfiedAction
2425
});
2526
}
2627

src/@episerver/forms-react/src/context/reducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export function formReducer(formState: FormState, action: any) {
3636
...formState,
3737
elementDependencies: formState.elementDependencies.map(fs => equals(fs.elementKey, action.elementKey) ? {
3838
elementKey: action.elementKey,
39-
isSatisfied: action.condition
39+
isSatisfied: action.condition,
40+
sastisfiedAction: action.satisfiedAction
4041
} as ElementDependencies : fs)
4142
} as FormState;
4243
}

src/@episerver/forms-react/src/hooks/useElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const useElement = (element: FormElementBase) => {
107107

108108
if (currentCondition != checkConditions) {
109109
// Update element dependencies state
110-
dispatchFuncs.UpdateElementDependencies(element.key, checkConditions);
110+
dispatchFuncs.UpdateElementDependencies(element.key, checkConditions, conditionProps.satisfiedAction);
111111
}
112112

113113
}, [formContext?.formSubmissions, formContext?.elementDependencies]);

src/@episerver/forms-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@episerver/forms-sdk",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Forms SDK with client validation, step navigation, submit form, element depends",
55
"author": "Optimizely",
66
"license": "ISC",

src/@episerver/forms-sdk/src/form-depend-conditions/ConditionFunctions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Equals(actualValue: any, dependencyFieldValue: string): boolean {
2929
* @returns
3030
*/
3131
function NotEquals(actualValue: any, dependencyFieldValue: string): boolean {
32-
const _actualValue = !actualValue ? "" : getConcatString(actualValue, ",").toLocaleUpperCase();
32+
const _actualValue = !actualValue ? "" : getConcatString(actualValue.toString(), ",").toLocaleUpperCase();
3333
dependencyFieldValue = !dependencyFieldValue ? "" : dependencyFieldValue.toLocaleUpperCase();
3434
return _actualValue !== dependencyFieldValue;
3535
}
@@ -40,7 +40,7 @@ function NotEquals(actualValue: any, dependencyFieldValue: string): boolean {
4040
* @returns
4141
*/
4242
function Contains(actualValue: any, dependencyFieldValue: string): boolean {
43-
const _actualValue = isNull(actualValue) ? "" : getConcatString(actualValue, ",").toLocaleUpperCase();
43+
const _actualValue = isNull(actualValue) ? "" : getConcatString(actualValue.toString(), ",").toLocaleUpperCase();
4444
dependencyFieldValue = !dependencyFieldValue ? "" : dependencyFieldValue.toLocaleUpperCase();
4545
return _actualValue.indexOf(dependencyFieldValue) >= 0;
4646
}
@@ -51,7 +51,7 @@ function Contains(actualValue: any, dependencyFieldValue: string): boolean {
5151
* @returns
5252
*/
5353
function NotContains(actualValue: any, dependencyFieldValue: string): boolean {
54-
const _actualValue = !actualValue ? "" : getConcatString(actualValue, ",").toLocaleUpperCase();
54+
const _actualValue = !actualValue ? "" : getConcatString(actualValue.toString(), ",").toLocaleUpperCase();
5555
const actualValueNull = isNullOrEmpty(_actualValue)
5656
const dependencyFieldValueNull = isNullOrEmpty(dependencyFieldValue)
5757
return (!actualValueNull && dependencyFieldValueNull) ||
@@ -66,6 +66,6 @@ function NotContains(actualValue: any, dependencyFieldValue: string): boolean {
6666
*/
6767
function MatchRegularExpression(actualValue: any, patternOfExpected: string): boolean {
6868
var regex = new RegExp(patternOfExpected, "igm");
69-
const _actualValue = !actualValue ? "" : getConcatString(actualValue, ",");
69+
const _actualValue = !actualValue ? "" : getConcatString(actualValue.toString(), ",");
7070
return isNullOrEmpty(patternOfExpected) || (!isNullOrEmpty(patternOfExpected) && regex.test(_actualValue));
7171
}

src/@episerver/forms-sdk/src/helpers/initFormState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function initFormState(formContainer: FormContainer, currentPageUrl?: str
2929
//init form submission
3030
formSubmissions = formSubmissions.concat({ elementKey: e.key, value: getDefaultValue(e) } as FormSubmission);
3131
//init form elements dependencies
32-
elementDependencies = elementDependencies.concat({ elementKey: e.key, isSatisfied: true });
32+
elementDependencies = elementDependencies.concat({ elementKey: e.key, isSatisfied: true, sastisfiedAction : (e.properties as any).satisfiedAction });
3333
}
3434
});
3535
stepDependencies = stepDependencies.concat({ elementKey: s.formStep.key, isSatisfied: false });
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface ElementDependencies{
22
elementKey: string
33
isSatisfied: boolean
4+
sastisfiedAction?: string
45
}

0 commit comments

Comments
 (0)