Skip to content

Commit

Permalink
Merge pull request #164 from episerver/master
Browse files Browse the repository at this point in the history
Merger Master to Develop
  • Loading branch information
linhhoangOpti authored Nov 8, 2024
2 parents 6a4a34f + 8026c7b commit 6df150c
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "content-headless-form-js-sdk",
"version": "1.0.0",
"version": "1.0.1",
"description": "Workspace root",
"workspaces": [
"src/@episerver/forms-react",
Expand Down
2 changes: 1 addition & 1 deletion src/@episerver/forms-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@episerver/forms-react",
"version": "1.0.0",
"version": "1.0.1",
"description": "Forms react components render a form from JSON data",
"author": "Optimizely",
"license": "ISC",
Expand Down
8 changes: 6 additions & 2 deletions src/@episerver/forms-react/src/components/FormBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useEffect, useRef } from "react";
import { useForms } from "../context/store";
import { StepHelper, FormContainer, FormSubmitter, IdentityInfo, isInArray, isNull,
isNullOrEmpty, FormSubmitModel, FormSubmitResult, SubmitButton, FormCache,
FormConstants, ProblemDetail, StepDependCondition, getConfirmationData } from "@episerver/forms-sdk";
FormConstants, ProblemDetail, StepDependCondition, getConfirmationData,
SatisfiedActionType} from "@episerver/forms-sdk";
import { RenderElementInStep } from "./RenderElementInStep";
import { DispatchFunctions } from "../context/dispatchFunctions";
import { FormStepNavigation } from "./FormStepNavigation";
Expand Down Expand Up @@ -102,7 +103,10 @@ export const FormBody = (props: FormBodyProps) => {

//get inactives element
let inactives = (formContext?.elementDependencies ?? [])
.filter(dependency => !dependency.isSatisfied)
.filter(dependency =>
(!dependency.isSatisfied && dependency.sastisfiedAction === SatisfiedActionType.Show)
|| (dependency.isSatisfied && dependency.sastisfiedAction === SatisfiedActionType.Hide)
)
.map(dependency => dependency.elementKey);

//filter submissions by active elements and current step
Expand Down
5 changes: 3 additions & 2 deletions src/@episerver/forms-react/src/context/dispatchFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ export class DispatchFunctions {
});
}

UpdateElementDependencies = (elementKey: string, condition: boolean) => {
UpdateElementDependencies = (elementKey: string, condition: boolean, satisfiedAction: string) => {
this._dispatch({
type: ActionType.UpdateElementDependencies,
elementKey: elementKey,
condition
condition,
satisfiedAction
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/@episerver/forms-react/src/context/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export function formReducer(formState: FormState, action: any) {
...formState,
elementDependencies: formState.elementDependencies.map(fs => equals(fs.elementKey, action.elementKey) ? {
elementKey: action.elementKey,
isSatisfied: action.condition
isSatisfied: action.condition,
sastisfiedAction: action.satisfiedAction
} as ElementDependencies : fs)
} as FormState;
}
Expand Down
2 changes: 1 addition & 1 deletion src/@episerver/forms-react/src/hooks/useElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const useElement = (element: FormElementBase) => {

if (currentCondition != checkConditions) {
// Update element dependencies state
dispatchFuncs.UpdateElementDependencies(element.key, checkConditions);
dispatchFuncs.UpdateElementDependencies(element.key, checkConditions, conditionProps.satisfiedAction);
}

}, [formContext?.formSubmissions, formContext?.elementDependencies]);
Expand Down
2 changes: 1 addition & 1 deletion src/@episerver/forms-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@episerver/forms-sdk",
"version": "1.0.0",
"version": "1.0.1",
"description": "Forms SDK with client validation, step navigation, submit form, element depends",
"author": "Optimizely",
"license": "ISC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Equals(actualValue: any, dependencyFieldValue: string): boolean {
* @returns
*/
function NotEquals(actualValue: any, dependencyFieldValue: string): boolean {
const _actualValue = !actualValue ? "" : getConcatString(actualValue, ",").toLocaleUpperCase();
const _actualValue = !actualValue ? "" : getConcatString(actualValue.toString(), ",").toLocaleUpperCase();
dependencyFieldValue = !dependencyFieldValue ? "" : dependencyFieldValue.toLocaleUpperCase();
return _actualValue !== dependencyFieldValue;
}
Expand All @@ -40,7 +40,7 @@ function NotEquals(actualValue: any, dependencyFieldValue: string): boolean {
* @returns
*/
function Contains(actualValue: any, dependencyFieldValue: string): boolean {
const _actualValue = isNull(actualValue) ? "" : getConcatString(actualValue, ",").toLocaleUpperCase();
const _actualValue = isNull(actualValue) ? "" : getConcatString(actualValue.toString(), ",").toLocaleUpperCase();
dependencyFieldValue = !dependencyFieldValue ? "" : dependencyFieldValue.toLocaleUpperCase();
return _actualValue.indexOf(dependencyFieldValue) >= 0;
}
Expand All @@ -51,7 +51,7 @@ function Contains(actualValue: any, dependencyFieldValue: string): boolean {
* @returns
*/
function NotContains(actualValue: any, dependencyFieldValue: string): boolean {
const _actualValue = !actualValue ? "" : getConcatString(actualValue, ",").toLocaleUpperCase();
const _actualValue = !actualValue ? "" : getConcatString(actualValue.toString(), ",").toLocaleUpperCase();
const actualValueNull = isNullOrEmpty(_actualValue)
const dependencyFieldValueNull = isNullOrEmpty(dependencyFieldValue)
return (!actualValueNull && dependencyFieldValueNull) ||
Expand All @@ -66,6 +66,6 @@ function NotContains(actualValue: any, dependencyFieldValue: string): boolean {
*/
function MatchRegularExpression(actualValue: any, patternOfExpected: string): boolean {
var regex = new RegExp(patternOfExpected, "igm");
const _actualValue = !actualValue ? "" : getConcatString(actualValue, ",");
const _actualValue = !actualValue ? "" : getConcatString(actualValue.toString(), ",");
return isNullOrEmpty(patternOfExpected) || (!isNullOrEmpty(patternOfExpected) && regex.test(_actualValue));
}
2 changes: 1 addition & 1 deletion src/@episerver/forms-sdk/src/helpers/initFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function initFormState(formContainer: FormContainer, currentPageUrl?: str
//init form submission
formSubmissions = formSubmissions.concat({ elementKey: e.key, value: getDefaultValue(e) } as FormSubmission);
//init form elements dependencies
elementDependencies = elementDependencies.concat({ elementKey: e.key, isSatisfied: true });
elementDependencies = elementDependencies.concat({ elementKey: e.key, isSatisfied: true, sastisfiedAction : (e.properties as any).satisfiedAction });
}
});
stepDependencies = stepDependencies.concat({ elementKey: s.formStep.key, isSatisfied: false });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ElementDependencies{
elementKey: string
isSatisfied: boolean
sastisfiedAction?: string
}

0 comments on commit 6df150c

Please sign in to comment.