@gadgetinc/react/auto 

The @gadgetinc/react/auto package powers Gadget autocomponents: beautiful auto-generated tables and forms pre-configured to read and write data using your Gadget app's auto-generated API.

The following is a comprehensive list of each autocomponent and its properties. Refer to the autocomponents guide for examples of how to use these components in your application.

The Gadget team is looking to create autocomponents from different design systems like MUI. Let the team know which design system we should add next on Discord.

<AutoTable /> 

The AutoTable component reads data from your database and renders each record as a row in the table. Pagination, search, and sorting are included in AutoTable components and are configurable with parameters.

React
// The only required prop is "model": this is the data model you wish to show the records of
// Use your Gadget API to pass in the model:
<AutoTable model={api.widget} />
// The only required prop is "model": this is the data model you wish to show the records of
// Use your Gadget API to pass in the model:
<AutoTable model={api.widget} />
Props 

The AutoTable component accepts the following props:

NameTypeDescription
modelModelFinderRequired. This is the data model you wish to show the records of. Ex: api.yourModelName
select?FieldSelectionA list of fields and subfields to select. This will override the default selection. See the Select option docs
pageSize?numberPage size of the paginated table. Defaults to 50
initialCursor?stringA string cursor; useTable handles pagination, this prop is only needed if you want to set the cursor to a custom spot
live?booleanChange the table in real time when a record is created/updated/deleted. Defaults to false
onClick?(row) => voidPerform a custom action when a table row is clicked
columns?string[] | CellDetailColumn[] | CustomCellColumn[]Columns to include in the table. Fields are passed as an array of strings by API identifiers. For relationships, you can choose which field of the related model to render using dot notation such as shopifyProduct.sku. HasMany relationships require a fully qualified GraphQL path, such as shopifyProduct.edges.node.sku. You can also pass a detailed column with a custom header, in this form: { header: string, field: string }, or a custom cell column: { header: string, render: (GadgetRecord<any>) => React.ReactNode }
excludeColumns?string[]A list of API identifiers for columns to exclude from the table
initialSort?{ [key: string]: "Ascending" | "Descending" }See the Sorting section in your application's API documentation for more info
filter?FilterObjectFilters to limit the set of returned records. Optional. See the Model Filtering section in your application's API documentation to see the available filters for your models
actions?(string | ActionCallback)[]List of actions that AutoTable can execute on the records it renders. This prop is a list of action API identifiers in string form or action callback objects which can have custom labels, be promoted buttons, or run a JavaScript function, where the ActionCallback type is in the form: {label: string, promoted?: true, action: string | ((records: GadgetRecord<any>[]) => any)}
excludeActions?string[]Actions to exclude from the AutoTable
selectable?booleanToggle whether rows are selectable. Defaults to true
emptyState?React.React.ReactNodeWhat to render when there are no records to populate the table
resourceName?{ singular: string; plural: string }The name of the resource that is populating the table. For example, if each row corresponds to a customer, resourceName would be { singular: "customer"; plural: "customers" }
searchable?booleanToggle whether the search bar is visible. Defaults to true
searchValue?stringOptional search value to programmatically search for the model records

Props passed to the components in different design systems:

<AutoForm /> 

<AutoForm /> renders a form that calls one of your app's backend API actions. You can use <AutoForm /> for model actions to create, update, or delete records. Global actions can also be called from <AutoForm />.

React
// The only required prop is "action": the action you wish to perform when the form is submitted
// Common actions are "create" & "update"
// These create/update a record based on the values entered in the form
<AutoForm action={api.widget.create} />
// The only required prop is "action": the action you wish to perform when the form is submitted
// Common actions are "create" & "update"
// These create/update a record based on the values entered in the form
<AutoForm action={api.widget.create} />
Props 
NameTypeDescription
actionActionFuncRequired. Which action this form will run on submit
titlestring | falseA custom form title, replacing the auto-generated title. Use false to hide the title
findBy?string | { [key: string]: any }Details for automatically finding a record to seed the form values. When passed as a string, will look up a record with that id. When passed an object, will call a findBy<Field> function on the api object to retrieve a record by that field. The field must have a uniqueness validation to function.
record?GadgetRecord<any>A record for this form to act on
include?string[]An allowlist of fields to render within the form. Only these fields will be rendered as inputs
exclude?string[]A denylist of fields to render within the form. Every field except these fields will be rendered as inputs
defaultValues?DefaultValuesA set of field values to pre-populate the form with on load. Only applies to create action forms. Must pass in fully-qualified path including the model name, for example: defaultValues={ { widget: { name: "foobar" } } }
submitLabel?React.ReactNodeThe label to use for the submit button at the bottom of the form
successContent?React.ReactNodeWhat to show the user once the form has been submitted successfully
onSuccess?(record) => voidCalled when the form submission completes successfully on the backend
onFailure?(error) => voidCalled when the form submission errors before sending, during the API call, or if the API call returns an error
select?FieldSelectionOverride control for selecting existing records with findBy. This is useful to prevent refetching when the form contains conditionally rendered inputs components

The AutoForm can be customized by adding children. Here's an example with the Polaris design system:

React
1import { AutoForm, AutoStringInput, AutoBooleanInput, AutoSubmit } from "@gadgetinc/react/auto/polaris";
2import { api } from "../api";
3
4export const MyCustomForm = () => {
5 return (
6 <>
7 <AutoForm action={api.customer.create}>
8 <h1>Subscribe to our newsletter!</h1>
9 <AutoStringInput field="email" />
10 <SubmitResultBanner />
11 <AutoSubmit />
12 </AutoForm>
13 </>
14 );
15};
1import { AutoForm, AutoStringInput, AutoBooleanInput, AutoSubmit } from "@gadgetinc/react/auto/polaris";
2import { api } from "../api";
3
4export const MyCustomForm = () => {
5 return (
6 <>
7 <AutoForm action={api.customer.create}>
8 <h1>Subscribe to our newsletter!</h1>
9 <AutoStringInput field="email" />
10 <SubmitResultBanner />
11 <AutoSubmit />
12 </AutoForm>
13 </>
14 );
15};

Adding custom children to an <AutoForm /> disables the title and submitLabel props and requires you to manually include the <AutoSubmit /> and <SubmitResultBanner /> components.

Custom selection and conditionally rendered inputs 

If you have an update action in an <AutoForm /> with custom child components, you may encounter a refetch for the existing record when the inputs appear conditionally. Consider a situation like this where you have a button that controls the appearance of some AutoInput components.

React
1// select prop to prevent refetching with conditionally rendered inputs
2const AutoFormWithCustomChildren = () => {
3 return (
4 <AutoForm
5 action={api.widget.update}
6 findBy="123"
7 select={
8 // The `select` prop overrides the default selection, which will not include the conditionally rendered inputs.
9 {
10 widget: {
11 name: true,
12 inventoryCount: true,
13 owner: {
14 // For relationship fields, select related model fields
15 id: true,
16 name: true,
17 },
18 },
19 }
20 }
21 >
22 <AutoInput field="name" />
23 <ConditionallyAppearingAutoInputs />
24 <AutoSubmit />
25 </AutoForm>
26 );
27};
28
29const ConditionallyAppearingAutoInputs = () => {
30 const [showMoreInputs, setShowMoreInputs] = useState(false);
31
32 return (
33 <>
34 <Button onClick={() => setShowMoreInputs(!showMoreInputs)}>{showMoreInputs ? "Hide" : "Show"} more inputs</Button>
35 {showMoreInputs && (
36 <>
37 {/* These fields are not included in the initial existing record selection by default. */}
38 {/* They will cause a refetch when rendered for the first time unless the `select` prop is used to includes these fields. */}
39 <AutoInput field="inventoryCount" />
40 <AutoInput field="owner" />
41 </>
42 )}
43 </>
44 );
45};
1// select prop to prevent refetching with conditionally rendered inputs
2const AutoFormWithCustomChildren = () => {
3 return (
4 <AutoForm
5 action={api.widget.update}
6 findBy="123"
7 select={
8 // The `select` prop overrides the default selection, which will not include the conditionally rendered inputs.
9 {
10 widget: {
11 name: true,
12 inventoryCount: true,
13 owner: {
14 // For relationship fields, select related model fields
15 id: true,
16 name: true,
17 },
18 },
19 }
20 }
21 >
22 <AutoInput field="name" />
23 <ConditionallyAppearingAutoInputs />
24 <AutoSubmit />
25 </AutoForm>
26 );
27};
28
29const ConditionallyAppearingAutoInputs = () => {
30 const [showMoreInputs, setShowMoreInputs] = useState(false);
31
32 return (
33 <>
34 <Button onClick={() => setShowMoreInputs(!showMoreInputs)}>{showMoreInputs ? "Hide" : "Show"} more inputs</Button>
35 {showMoreInputs && (
36 <>
37 {/* These fields are not included in the initial existing record selection by default. */}
38 {/* They will cause a refetch when rendered for the first time unless the `select` prop is used to includes these fields. */}
39 <AutoInput field="inventoryCount" />
40 <AutoInput field="owner" />
41 </>
42 )}
43 </>
44 );
45};

A refetch will occur when the AutoInput components with inventoryCount and owner get rendered for the first time. To prevent this refetch, you can use the select prop in <AutoForm /> to override the default selection behavior to include all field inputs that can be potentially rendered in the form.

<AutoInput /> 

This input detects the type of the field, and renders the correct input type. If the field is of type date / time, the AutoInput will return a date/time picker.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render.
label?ReactNodeCustom label for the input.

If you wish to customize the AutoInput further, use the input that corresponds to the type of the field.

<AutoHiddenInput /> 

The hidden input allows you to add to the form submission without rendering an input. An example would be including user preferences in a hidden input. When a user submits the form, their preferences are included in the form submission without any extra input from them.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a file input.
value?anyValue of the hidden input. Users cannot change this directly.

<AutoBooleanInput /> 

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a checkbox. The field must be of type boolean.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoDateTimePicker /> 

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a date/time picker. The field must be of type date / time.
label?ReactNodeCustom label for the input.
error?stringError message to display.
hideTimePopover?booleanHide the popover that shows the currently selected time. Defaults to false.
datePickerProps?DatePickerPropsFull props list can be found in the Polaris Date Picker docs.
timePickerProps?TimePickerPropsThe time picker takes the same props as a Polaris text field.

Props passed to the components by different design systems:

<AutoEncryptedStringInput /> 

A component that allows users to enter strings which they want to encrypt.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as an input. The field must be of type encrypted string.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoEnumInput /> 

A component that allows the user to select one or more options.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as an input. The field must be of type enum.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoFileInput /> 

A file input box.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a file input. The field must be of type file.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoJSONInput /> 

An input with built-in JSON validation.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a JSON input. The field must be of type json.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoNumberInput /> 

A text field, with number validations.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a number input. The field must be of type number.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoPasswordInput /> 

A text field, with special validations for passwords. Upon submission, inputs are encrypted and stored in a shared Postgres database hosted by Gadget.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a password input. Each character will be rendered as a dot by default. The field must be of type password.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoRolesInput /> 

A Gadget app has one global list of roles that governs permissions across the application. This input allows users to select the roles that have been defined. Learn more about roles and access control here.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a combobox. The field must be of type role list.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoEmailInput /> 

A text field that has validations so it only accepts strings that have a valid email format.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a text input. The field must be of type email.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoStringInput /> 

A text field that accepts any string.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a text input. The field must be of type string.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoUrlInput /> 

A text input with builtin validation for URLs.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a text input. The field must be of type url.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

Props passed to the components by different design systems:

<AutoRichTextInput /> 

A text input for rich text fields, powered by MDXEditor.

NOTE: The "@mdxeditor/editor": "^3.8.0", dependency must be in your project's package.json file to use this component.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render as a text input. The field must be of type rich text.
label?ReactNodeCustom label for the input.
control?Control<any>Control object from the React Hook Form library.

There are currently no props passed to the MDX editor by different design systems.

<AutoButton /> 

<AutoButton /> renders a button that calls one of your app's backend API actions onClick. You can use <AutoButton /> for model actions to create, update, or delete records, or to call a global action.

NameTypeDescription
actionActionFuncRequired. Which action will run when the form is submitted.
variables?anyThe variables to pass to the action when run. See the <AutoButton /> guide for examples on how to pass in variables.
onSuccess?(result) => voidCallback function to run when the button succeeded at running the action. Overrides the default behavior of rendering a message to the user to display success.
onError?(result) => voidCallback function to run when the button failed at running the action with an error. Overrides the default behavior of rendering a message to the user to display the error.

Props passed to the components by different design systems:

<AutoSubmit /> 

Submits the AutoForm onClick.

NameTypeDescription
children?React.ReactNodeChildren can be passed to <AutoSubmit /> to customize its label.
isSubmitting?booleanLoading state of the submit button. The button will render a spinner while isSubmitting is true.

Props passed to the components by different design systems:

<SubmitResultBanner /> 

The customizable banner users see when they submit your AutoForm.

NameTypeDescription
successfulBannerProps?Polaris.BannerPropsWhat banner to render when the form is submitted successfully.
errorBannerProps?Polaris.BannerPropsWhat banner to render when the form is submitted unsuccessfully.

Props passed to the components by different design systems:

The props list for Polaris.BannerProps can be found here.

Relationship inputs 

<AutoBelongsToInput /> 

The <AutoBelongsToInput /> component allows users to pick records on the related model to associate with this belongs to field.

If the Gadget backend has a field like this:

<AutoBelongsToInput /> will render it like this:

Each email is taken from a record in the customer table. The autocomponents system labelled the options with the customer's email. To render a custom label, use the optionLabel prop. This component requires the read and update permissions.

custom option label
React
1<AutoForm action={api.purchase.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `customer` field on `purchase` model */}
4 <AutoBelongsToInput field="customer" optionLabel={(record: { id: string }) => `Customer ${record.id}`} />
5 <AutoSubmit />
6</AutoForm>
1<AutoForm action={api.purchase.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `customer` field on `purchase` model */}
4 <AutoBelongsToInput field="customer" optionLabel={(record: { id: string }) => `Customer ${record.id}`} />
5 <AutoSubmit />
6</AutoForm>
NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type belongs to.
control?Control<any>Control object from the React Hook Form library.
label?ReactNodeA custom label for the input.
optionLabel?OptionLabelType for the option label when displaying a list of records from a related model. API identifier, array of API identifiers or a callback function returning a React node. Defaults to fields named name, title, or email with a fallback to any string field and finally the id.
recordFilter?RecordFilterRelated record option filter.

<AutoHasOneInput /> 

The <AutoHasOneInput /> component allows users to pick a single record from the related model. The relationship is defined on by the belongs to field on the child model, and the 1:1 mapping between records will be maintained.

React
1<AutoForm action={api.car.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `engine` field on `car` model */}
4 <AutoHasOneInput field="engine" label="Engine" />
5 <AutoSubmit />
6</AutoForm>
1<AutoForm action={api.car.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `engine` field on `car` model */}
4 <AutoHasOneInput field="engine" label="Engine" />
5 <AutoSubmit />
6</AutoForm>

The has one relationship will be updated by changing the ID value stored in the belongs to field on the related model. The related model will require the update permission.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type has one.
control?Control<any>Control object from the React Hook Form library.
label?ReactNodeA custom label for the input.
optionLabel?OptionLabelType for the option label when displaying a list of records from a related model. API identifier, array of API identifiers or a callback function returning a React node. Defaults to fields named name, title, or email with a fallback to any string field and finally the id.
recordFilter?RecordFilterRelated record option filter.

Use the recordFilter prop to help avoid unlinking a relationship between already linked parent and child records.

<AutoHasManyInput /> 

The <AutoHasManyInput /> component allows users to pick records from the related model to associate with the current record.

A multi-select combobox is used. If AutoForm is associated the some model customer, each purchase that is selected belongs to the customer model.

The purchase model has a belongs to relationship with the customer model. The purchase model needs the read permission to use this input.

React
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" label="Name" />
5 {/* `textbooks` field on `course` model */}
6 <AutoHasManyInput field="textbooks" label="Textbooks" />
7 <AutoSubmit />
8</AutoForm>
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" label="Name" />
5 {/* `textbooks` field on `course` model */}
6 <AutoHasManyInput field="textbooks" label="Textbooks" />
7 <AutoSubmit />
8</AutoForm>

Note that selecting a new parent for a child record will unlink the child from the previous parent. Use the recordFilter prop to help avoid unlinking a relationship between already linked parent and child records by filtering out any records with a parent relationship.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type has many.
control?Control<any>Control object from the React Hook Form library.
label?ReactNodeA custom label for the input.
optionLabel?OptionLabelType for the option label when displaying a list of records from a related model. API identifier, array of API identifiers or a callback function returning a React node. Defaults to fields named name, title, or email with a fallback to any string field and finally the id.
recordFilter?RecordFilterRelated record option filter.

<AutoHasManyThroughInput /> 

The <AutoHasManyThroughInput /> component allows users to select records from the related model and make associations through creating and removing records in the join model. The join model has a belongs to field associated with the current model's has many through field, and another belongs to field associated with the related model's has many through field. A relationship between the current model and the related model is defined by the existence of a record in the join model that is associated with the corresponding current model record and related model record.

React
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" />
5 {/* `students` field on `course` model - `course` hasMany `students` through `registration` */}
6 <AutoHasManyThroughInput field="students" label="Students" />
7 <AutoSubmit />
8</AutoForm>
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" />
5 {/* `students` field on `course` model - `course` hasMany `students` through `registration` */}
6 <AutoHasManyThroughInput field="students" label="Students" />
7 <AutoSubmit />
8</AutoForm>

This input requires that you add a few different permissions to the access control page. The model with the hasManyThrough relationship and the join model must have all permissions enabled in order to use this input. The sibling model must have the read permission enabled.

Note that the recordFilter prop only applies to sibling model selection dropdown in the case of the has many through relationship.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type has many through.
control?Control<any>Control object from the React Hook Form library.
label?ReactNodeA custom label for the input.
optionLabel?OptionLabelType for the option label when displaying a list of records from a related model. API identifier, array of API identifiers or a callback function returning a React node. Defaults to fields named name, title, or email with a fallback to any string field and finally the id.
recordFilter?RecordFilterRelated record option filter.

Relationship forms 

Relationship forms are AutoForm input components that allow users to create, update, and delete related records through the relationship fields of an action's model.

<AutoBelongsToForm /> 

The <AutoBelongsToForm /> component allows users to select, create, or edit a record associated with the current record through a belongs to field.

React
1<AutoForm action={api.productVariant.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `productVariant` model */}
4 <AutoInput field="name" />
5 {/* `product` field on `productVariant` model - belongsTo field */}
6 <AutoBelongsToForm field="product">
7 {/* `name` field on `product` model */}
8 <AutoInput field="name" />
9 </AutoBelongsToForm>
10 <AutoSubmit />
11</AutoForm>
1<AutoForm action={api.productVariant.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `productVariant` model */}
4 <AutoInput field="name" />
5 {/* `product` field on `productVariant` model - belongsTo field */}
6 <AutoBelongsToForm field="product">
7 {/* `name` field on `product` model */}
8 <AutoInput field="name" />
9 </AutoBelongsToForm>
10 <AutoSubmit />
11</AutoForm>

Using a <AutoBelongsToForm/> component requires the read, create, and update permissions on related model.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type belongs to.
childrenReactNodeNested elements or components of the current component.
label?ReactNodeA custom label for the relationship form.
recordLabel?OptionLabel | RecordLabelThe label configuration when displaying a selected record or an option record from a related model. This can be an API identifier, array of API identifiers, or a callback function that takes the record and returns a React node.
recordFilter?RecordFilterRelated record option filter.

<AutoHasOneForm /> 

The <AutoHasOneForm /> component allows users to create, update, or unlink a record in the related model through a has one relationship. The relationship is defined on by the belongs to field on the related child model, and the 1:1 mapping between records will be maintained.

Unlinking the related record in a has one relationship is done by updating the related record's ID value in the corresponding belongs to field to be null. To use the <AutoHasOneForm /> component, the related model must have the read, create, and update permissions.

React
1<AutoForm action={api.car.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `engine` field on `car` model */}
4 <AutoHasOneForm field="engine">
5 {/* `horsepower` field on `engine` model */}
6 <AutoInput field="horsepower" />
7 </AutoHasOneForm>
8 <AutoSubmit />
9</AutoForm>
1<AutoForm action={api.car.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `engine` field on `car` model */}
4 <AutoHasOneForm field="engine">
5 {/* `horsepower` field on `engine` model */}
6 <AutoInput field="horsepower" />
7 </AutoHasOneForm>
8 <AutoSubmit />
9</AutoForm>
NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type has one.
childrenReactNodeNested elements or components of the current component.
label?ReactNodeA custom label for the relationship form.
recordLabel?OptionLabel | RecordLabelThe label configuration when displaying a record from the related model. This can be an API identifier, array of API identifiers, or a callback function that takes the record and returns a React node.

<AutoHasManyForm /> 

The <AutoHasManyForm /> component allows users to create, update, and delete related child records through a has many relationship field. When child records are unlinked in the <AutoHasManyForm /> component, they are deleted.

React
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" label="Name" />
5 {/* `textbooks` field on `course` model */}
6 <AutoHasManyForm field="textbooks">
7 {/* `title` field on the `textbook` model */}
8 <AutoInput field="title" label="Title" />
9 </AutoHasManyForm>
10 <AutoSubmit />
11</AutoForm>
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" label="Name" />
5 {/* `textbooks` field on `course` model */}
6 <AutoHasManyForm field="textbooks">
7 {/* `title` field on the `textbook` model */}
8 <AutoInput field="title" label="Title" />
9 </AutoHasManyForm>
10 <AutoSubmit />
11</AutoForm>

The <AutoHasManyForm /> component requires the read, create, update and delete permissions to the related model.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type has many.
childrenReactNodeNested elements or components of the current component.
label?ReactNodeA custom label for the relationship form.
recordLabel?OptionLabel | RecordLabelThe label configuration when displaying a records from the related model. This can be an API identifier, array of API identifiers, or a callback function that takes the record and returns a React node.

<AutoHasManyThroughForm /> 

The <AutoHasManyThroughForm /> component allows users to create, update, and delete associations with the sibling model through the join model. Associations between the current model and the sibling model are defined by the two belongs to fields on the join model that point to the current model and the sibling model.

React
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" />
5 {/* `students` field on `course` model - `course` hasMany `students` through `registration` */}
6 <AutoHasManyThroughForm field="students">
7 {/* Join model field inputs */}
8 <AutoHasManyThroughJoinModelForm>
9 <AutoInput
10 // `isTuitionPaid` field on `registration` model
11 field="isTuitionPaid"
12 />
13 </AutoHasManyThroughJoinModelForm>
14
15 {/* Sibling model field inputs */}
16 <AutoInput
17 // `firstName` field on `student` model
18 field="firstName"
19 />
20 </AutoHasManyThroughForm>
21 <AutoSubmit />
22</AutoForm>
1<AutoForm action={api.course.update} findBy="1">
2 <SubmitResultBanner />
3 {/* `name` field on `course` model */}
4 <AutoInput field="name" />
5 {/* `students` field on `course` model - `course` hasMany `students` through `registration` */}
6 <AutoHasManyThroughForm field="students">
7 {/* Join model field inputs */}
8 <AutoHasManyThroughJoinModelForm>
9 <AutoInput
10 // `isTuitionPaid` field on `registration` model
11 field="isTuitionPaid"
12 />
13 </AutoHasManyThroughJoinModelForm>
14
15 {/* Sibling model field inputs */}
16 <AutoInput
17 // `firstName` field on `student` model
18 field="firstName"
19 />
20 </AutoHasManyThroughForm>
21 <AutoSubmit />
22</AutoForm>

By default, AutoForm inputs within a <AutoHasManyThroughForm> will be associated with fields on the sibling model. To associate inputs with fields on the join model, wrap your AutoForm inputs with the <AutoHasManyThroughJoinModelForm /> component.

The <AutoHasManyThroughForm /> component requires the read, create, update, and delete permissions to the join model, and the read and update permissions to the sibling model.

NameTypeDescription
fieldstringRequired. API identifier of the field you wish to render. The field must be of type has many through.
children?ReactNodeNested elements or components of the current component.
label?ReactNodeA custom label for the relationship form.
recordLabel?OptionLabel | RecordLabelThe option label configuration when displaying a associated records and record options from the sibling model. This can be an API identifier, array of API identifiers, or a callback function that takes the sibling model record and returns a React node.
recordFilter?RecordFilterRelated record option filter. This applies to the sibling model selection dropdown.

Types 

NameTypeDescription
OptionLabelstring | string[] | ((record: Record<string, any>) => ReactNode)Type for the option label when displaying a list of records from a related model. API identifier, array of API identifiers or a callback function returning a React node. Defaults to fields named name, title, or email with a fallback to any string field and finally the id.
RecordLabel{ primary?: OptionLabel; secondary?: OptionLabel; tertiary?: OptionLabel }Type for the option label when displaying a list of records from a related model. API identifier, array of API identifiers or a callback function returning a React node. Displayed like the title of a section.
RecordFilterAnyFilter | AnyFilter[] | undefinedFilters that can be applied on a query to the database.

Was this page helpful?