Skip to content

Commit

Permalink
Merge pull request #4578 from easyops-cn/jimmy/fix/form-renderer
Browse files Browse the repository at this point in the history
fix(): form-renderer 支持 getFieldsValue 方法
  • Loading branch information
qiaofengxi authored Dec 12, 2024
2 parents 4df20c8 + eb4453d commit 37f9597
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ describe("registerFormRenderer is work", () => {

expect(form.resetFields).toHaveBeenCalled();
});

it("should work with getFieldsValue method", () => {
const formRender = document.createElement(formRenderer) as any;
formRender.renderRoot = false;
const form = document.createElement("forms.general-form") as any;
form.getFieldsValue = jest.fn();

formRender.appendChild(form);

formRender.getFieldsValue({ runInMacrotask: true });

expect(form.getFieldsValue).toHaveBeenCalledWith({ runInMacrotask: true });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FormElement extends HTMLElement implements FormElementProps {

renderRoot?: boolean | undefined;

#proxyFormMethod(method: string, args: unknown[] = []): void {
#proxyFormMethod(method: string, args: unknown[] = []): any {
const containerElement =
this.renderRoot !== false
? this.firstElementChild?.firstElementChild
Expand All @@ -21,7 +21,7 @@ class FormElement extends HTMLElement implements FormElementProps {
const tagName = containerElement?.tagName?.toLowerCase();

if (formContainers.includes(tagName as string)) {
(containerElement as any)[method](...args);
return (containerElement as any)[method](...args);
} else {
// eslint-disable-next-line no-console
console.error(`no ${method} method in the container element`, {
Expand All @@ -41,6 +41,10 @@ class FormElement extends HTMLElement implements FormElementProps {
resetFields(...args: unknown[]): void {
this.#proxyFormMethod("resetFields", args);
}

getFieldsValue(...args: unknown[]): any {
return this.#proxyFormMethod("getFieldsValue", args);
}
}

export function registerFormRenderer(): void {
Expand Down

0 comments on commit 37f9597

Please sign in to comment.