Skip to content

Commit

Permalink
fix(ui-tablemode): create modal is frozen when submitting without col…
Browse files Browse the repository at this point in the history
…umn (#1946)
  • Loading branch information
skamril authored Feb 26, 2024
1 parent 9887787 commit a351458
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions webapp/src/components/common/fieldEditors/ListFE/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import reactHookFormSupport, {
import {
createFakeBlurEventHandler,
createFakeChangeEventHandler,
createFakeInputElement,
FakeBlurEventHandler,
FakeChangeEventHandler,
FakeHTMLInputElement,
InputObject,
} from "../../../../utils/feUtils";
import { makeLabel, makeListItems } from "./utils";

Expand Down Expand Up @@ -97,7 +98,7 @@ function ListFE<TItem, TOption>(props: ListFEProps<TItem, TOption>) {
// Trigger event handlers
useUpdateEffect(() => {
if (onChange || onBlur) {
const fakeInputElement: FakeHTMLInputElement = {
const fakeInputElement: InputObject = {
value: listItems.map((item) => item.value),
name,
};
Expand All @@ -108,10 +109,10 @@ function ListFE<TItem, TOption>(props: ListFEProps<TItem, TOption>) {

// Set ref
useEffect(() => {
const fakeInputElement: FakeHTMLInputElement = {
const fakeInputElement = createFakeInputElement({
value: listItems.map((item) => item.value),
name,
};
});
setRef(inputRef, fakeInputElement);
}, [inputRef, listItems, name]);

Expand Down
12 changes: 10 additions & 2 deletions webapp/src/utils/feUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { HTMLInputTypeAttribute } from "react";

export interface FakeHTMLInputElement {
export interface InputObject {
value: unknown;
checked?: boolean;
type?: HTMLInputTypeAttribute;
name?: string;
}

type Target = HTMLInputElement | FakeHTMLInputElement;
type Target = HTMLInputElement | InputObject;

export interface FakeChangeEventHandler {
target: Target;
Expand Down Expand Up @@ -36,3 +36,11 @@ export function createFakeBlurEventHandler(
type: "blur",
};
}

export function createFakeInputElement(obj: InputObject): HTMLInputElement {
const inputElement = document.createElement("input");
inputElement.name = obj.name || "";
inputElement.value = obj.value as string;

return inputElement;
}

0 comments on commit a351458

Please sign in to comment.