Skip to content

Commit

Permalink
Merge pull request #132 from episerver/bugfix/aform-3947-initial-form…
Browse files Browse the repository at this point in the history
…-focus-doesnt-work

Fix InitialFormFocus doesn't work
  • Loading branch information
epi-qang2 authored Jun 17, 2024
2 parents d66e015 + fb02fda commit 2eeeb3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/@episerver/forms-react/src/components/FormBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ export const FormBody = (props: FormBodyProps) => {
//reset when change page
useEffect(() => {
isSuccess.current = false;
if (form.properties.focusOnForm || currentStepIndex > 0){
dispatchFunctions.updateFocusOn(stepHelper.getFirstInputElement(currentStepIndex, inactiveElements));
}
}, [currentStepIndex]);

//Run in-case change page by url. The currentStepIndex that get from cache is incorrect.
Expand Down
12 changes: 12 additions & 0 deletions src/@episerver/forms-sdk/src/helpers/stepHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ export class StepHelper {
}
return !isNullOrEmpty(step.properties?.dependField?.key)
}

/**
* Get the first input elementKey in the list element
* @param stepIndex
* @returns
*/
getFirstInputElement(stepIndex: number, inactiveElements: string[]): string {
const arrInputElement = this._form.steps[stepIndex].elements.find((e) =>
e.contentType.indexOf("ElementBlock") > 0 && inactiveElements.indexOf(e.key) < 0
);
return arrInputElement?.key ?? "";
}
}
3 changes: 2 additions & 1 deletion src/@episerver/forms-sdk/src/models/FormContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export interface FormContainerProperties {
allowMultipleSubmission: boolean
showNavigationBar : boolean
description: string
metadataAttribute: string
metadataAttribute: string,
focusOnForm: boolean;
}

export interface Step {
Expand Down

0 comments on commit 2eeeb3b

Please sign in to comment.