Skip to content

Commit

Permalink
reset form data if formsPath change
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Mar 19, 2024
1 parent 3256fdd commit 331bef3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Resolve,
} from "@jsonforms/core";
import merge from "lodash/merge";
import React, { useCallback, useMemo, useState } from "react";
import React, {useCallback, useEffect, useMemo, useState} from "react";

import { ArrayLayoutToolbar } from "./ArrayToolbar";
import { useJsonForms } from "@jsonforms/react";
Expand Down Expand Up @@ -120,6 +120,15 @@ const MaterialArrayChipsLayoutComponent = (props: ArrayLayoutProps & {}) => {

const isReifiedStatement = Boolean(appliedUiSchemaOptions.isReifiedStatement);

const formsPath = useMemo(
() => makeFormsPath(config?.formsPath, path),
[config?.formsPath, path],
);

useEffect(() => {
setFormData( irisToData(slent(uuidv4()).value, typeIRI))
}, [formsPath, typeIRI,setFormData]);

return (
<Box
sx={(theme) => ({
Expand Down Expand Up @@ -156,7 +165,7 @@ const MaterialArrayChipsLayoutComponent = (props: ArrayLayoutProps & {}) => {
entityIRI && setFormData({ "@id": entityIRI })
}
onFormDataChange={(data) => setFormData(data)}
formsPath={makeFormsPath(config?.formsPath, path)}
formsPath={formsPath}
/>
)}
{isReifiedStatement && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps & {}) => {
[config?.formsPath, path],
);

useEffect(() => {
setFormData( irisToData(slent(uuidv4()).value, typeIRI))
}, [formsPath, typeIRI,setFormData]);

return (
<div>
<ArrayLayoutToolbar
Expand Down

0 comments on commit 331bef3

Please sign in to comment.