Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hidden element when a condition change #151

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/@episerver/forms-react/src/hooks/useElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ export const useElement = (element: FormElementBase) => {
//update form state
dispatchFuncs.resetFormDone();
}
},[formContext?.isReset]);
}, [formContext?.isReset]);

//update visible
useEffect(()=>{
useEffect(() => {
const conditionProps = (element.properties as unknown) as ConditionProperties;

if (isNull(conditionProps.satisfiedAction)) {
if (isNull(conditionProps.satisfiedAction) || isNull(conditionProps.conditions)) {
// No conditions and satisfied actions to take, no need to update dependencies
return;
}

Expand All @@ -102,16 +103,19 @@ export const useElement = (element: FormElementBase) => {
//if isDependenciesSatisfied = false, and if SatisfiedAction = hide, then show element. otherwise hide element.
isVisible.current = equals(conditionProps.satisfiedAction, SatisfiedActionType.Hide);
}
var currentCondition = formContext?.elementDependencies.find(e => e.elementKey === element.key)?.isSatisfied;

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

// Update element dependencies state
dispatchFuncs.UpdateElementDependencies(element.key,checkConditions);

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

//focus on element if validate fail before submitting
useEffect(()=>{
useEffect(() => {
let focusOn = formContext?.focusOn ?? "";
if(equals(focusOn, element.key)){
if (equals(focusOn, element.key)) {
elementRef.current && elementRef.current.focus();
dispatchFuncs.updateFocusOn("");
}
Expand Down
Loading