Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(ui) Improve docs for Form component #28605

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions static/app/views/settings/components/forms/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,65 @@ type RenderProps = {
type RenderFunc = (props: RenderProps) => React.ReactNode;

type Props = {
/**
* The HTTP method to use.
*/
apiMethod?: APIRequestMethod;
/**
* The URL to the API endpoint this form submits to.
*/
apiEndpoint?: string;
children?: React.ReactNode | RenderFunc;
className?: string;
cancelLabel?: string;
/**
* Should the submit button be disabled.
*/
submitDisabled?: boolean;
submitLabel?: string;
submitPriority?: React.ComponentProps<typeof Button>['priority'];
footerClass?: string;
footerStyle?: React.CSSProperties;
extraButton?: React.ReactNode;
initialData?: Data;
// Require changes before able to submit form
/**
* Are changed required before the form can be submitted.
*/
requireChanges?: boolean;
// Reset form when there are errors; after submit
/**
* Should the form reset its state when there are errors after submission.
*/
resetOnError?: boolean;
hideFooter?: boolean;
allowUndo?: boolean;
// Save field on control blur
/**
* Should fields save individually as they are blurred.
*/
saveOnBlur?: boolean;
/**
* A FormModel instance. If undefined a FormModel will be created for you.
*/
model?: FormModel;
// if set to true, preventDefault is not called
/**
* If set to true, preventDefault is not called
*/
skipPreventDefault?: boolean;
additionalFieldProps?: {[key: string]: any};
'data-test-id'?: string;

/**
* Callback fired when the form is cancelled via the cancel button.
*/
onCancel?: (e: React.MouseEvent) => void;
/**
* Callback to handle form submission.
*
* Defining this prop will replace the normal API submission behavior
* and instead only call the provided callback.
*
* Your callback is expected to call `onSubmitSuccess` when the action succeeds and
* `onSubmitError` when the action fails.
*/
onSubmit?: (
data: Data,
onSubmitSuccess: (data: Data) => void,
Expand Down