KeyboundForm - Admin Components
Note: This component is available since Medusa v2.21.0.
The KeyboundForm component is a form element that submits only when the user presses ⌘+Enter. The Medusa Admin uses it in its modals and drawers so that pressing Enter in a field doesn't submit the form by accident.
Example#
Use KeyboundForm in place of a native form element inside a Form component, as shown in the Forms guide:
import {
Form,
KeyboundForm,
} from "@medusajs/dashboard/components"
import { Button, Input } from "@medusajs/ui"
import { useForm } from "react-hook-form"
const BrandForm = () => {
const form = useForm({
defaultValues: {
name: "",
},
})
const handleSubmit = form.handleSubmit(async (data) => {
console.log(data)
})
return (
<Form {...form}>
<KeyboundForm onSubmit={handleSubmit}>
<Form.Field
control={form.control}
name="name"
render={({ field }) => (
<Form.Item>
<Form.Label>Name</Form.Label>
<Form.Control>
<Input {...field} />
</Form.Control>
<Form.ErrorMessage />
</Form.Item>
)}
/>
<Button type="submit">Save</Button>
</KeyboundForm>
</Form>
)
}
The user can still submit the form by clicking the submit button. When the user presses Enter in a field, KeyboundForm prevents the default submission. In a textarea, pressing Enter inserts a new line instead.
Props#
accepts the same props as a native element, including the following:
Loading...
KeyboundForm also accepts every other attribute of a native form element, such as id, className, and noValidate.
Was this page helpful?