Skip to content

Commit

Permalink
fix: make SelectParentWidget clear properly
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Apr 27, 2022
1 parent bd49797 commit 32180f8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/lib/theme/widgets/SelectParentWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Dropdown from "@button-inc/bcgov-theme/Dropdown";
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { WidgetProps } from "@rjsf/core";

export interface EntitySchema {
Expand Down Expand Up @@ -27,11 +27,14 @@ const SelectParentWidget: React.FunctionComponent<
child,
foreignKey,
}) => {
const parentValue = child.list.find((opt) => opt.rowId == parseInt(value))?.[
foreignKey
];
const parentValue =
child.list.find((opt) => opt.rowId == parseInt(value))?.[foreignKey] || "";
const [selectedParentId, setSelectedParentId] = useState(parentValue);

useEffect(() => {
setSelectedParentId(parentValue);
}, [parentValue]);

const onParentChange = (val) => {
setSelectedParentId(parseInt(val));
if (!parseInt(val)) onChange(undefined);
Expand Down

0 comments on commit 32180f8

Please sign in to comment.