Skip to content

Commit

Permalink
fix(react-formio): Fix issue on Form hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Feb 23, 2021
1 parent 0b47eea commit 80543f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export function FormAccess({
onSubmit,
options
}: PropsWithChildren<FormAccessProps>): ReactElement {
const submissionAccess = {
data: formAccessToSubmission(form.submissionAccess)
};
const access = { data: formAccessToSubmission(form.access) };

return (
<div>
{children}
Expand All @@ -35,7 +40,7 @@ export function FormAccess({
form={getSubmissionPermissionForm({
choices: mapRoles(roles)
})}
submission={{ data: formAccessToSubmission(form.submissionAccess) }}
submission={submissionAccess}
onSubmit={(data: any) => {
onSubmit(mapSubmissionAccess("submissionAccess", form, data));
}}
Expand Down Expand Up @@ -82,11 +87,11 @@ export function FormAccess({
form={getAccessPermissionForm({
choices: mapRoles(roles)
})}
submission={{ data: formAccessToSubmission(form.access) }}
submission={access}
onSubmit={(data: any) => {
onSubmit(mapSubmissionAccess("access", form, data));
}}
options={{ ...{ template: "bootstrap3", iconset: "fa" } }}
options={options}
/>

{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default {
export const Sandbox = (args: any) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
return <FormAccess {...args} />;
return (
<FormAccess {...args} options={{ template: "tailwind", iconset: "bx" }} />
);
};

Sandbox.args = {
Expand All @@ -48,7 +50,12 @@ Sandbox.args = {
type: "read_all"
}
],
submissionAccess: [],
submissionAccess: [
{
roles: ["5d0797bc872fc747da559858"],
type: "read_all"
}
],
controller: "",
properties: {},
settings: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
component: FormAction,
argTypes: {
onSubmit: { action: "onSubmit" },

type: {
control: {
type: "object"
Expand Down
7 changes: 6 additions & 1 deletion packages/react-formio/src/components/form/useForm.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const useForm = ({
const initializeFormio = (): void => {
if (instance.current && instance.current.ready) {
instance.current.onAny(onAnyEvent);
if (submission) {

if (formio.current && submission) {
formio.current.submission = submission;
}
}
Expand All @@ -58,6 +59,10 @@ export const useForm = ({
onFormReady(formioInstance);
}

if (submission) {
formio.current.submission = submission;
}

return formio.current;
};

Expand Down

0 comments on commit 80543f1

Please sign in to comment.