Skip to content

Commit c254187

Browse files
zepatrikamcasey
authored andcommitted
add submit method to Form (DefinitelyTyped#37979)
1 parent 83e5c8c commit c254187

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

types/react-jsonschema-form/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ declare module 'react-jsonschema-form' {
5656
acceptcharset?: string;
5757
}
5858

59-
export default class Form<T> extends React.Component<FormProps<T>> {}
59+
export default class Form<T> extends React.Component<FormProps<T>> {
60+
submit: () => void;
61+
}
6062

6163
export type UiSchema = {
6264
'ui:field'?: Field | string;

types/react-jsonschema-form/react-jsonschema-form-tests.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,15 @@ export const withThemeExample = () => {
173173
export const additionalPropertyFlagExample = () => {
174174
return ADDITIONAL_PROPERTY_FLAG;
175175
};
176+
177+
export const ExternalFormSubmissionExample = () => {
178+
const formRef = React.useRef<Form<any>>(null);
179+
180+
return (
181+
<Form schema={schema} ref={formRef}>
182+
<button onClick={formRef.current ? formRef.current.submit : undefined}>
183+
FancySubmitButton
184+
</button>
185+
</Form>
186+
);
187+
};

0 commit comments

Comments
 (0)