Form Component
The <Form> component provides a structured layout for forms, seamlessly integrating with the useForm hook. It handles the form submission, displays submit and optional cancel buttons.
Basic Usage
The component renders a <form> element. Wrap your form fields within the <Form> component.
import { Form, InputField } from "react-better-html";
function LoginForm() {
return (
<Form submitButtonText="Login" gap={10} onSubmit={(event) => {}}>
<InputField label="Username" name="username" />
<InputField.password label="Password" name="password" />
</Form>
);
}
Common Props
form- the object returned by theuseFormhook.submitButtonText- the text to display on the submit button. If provided, a submit button will be rendered.submitButtonLoaderName- the name of the loader to display on the submit button.submitButtonId- theidattribute for the submit button.submitButtonIsDisabled- a boolean to manually disable the submit button. This prop takes precedence over the automatic disabling based on required fields.actionButtonsLocation- controls the horizontal alignment of the action buttons (submit and cancel).gap- the gap between the child elements within the form.isSubmitting- a boolean to manually control the loading state of the submit button. This is typically managed by theisSubmittingstate returned by theuseFormhook.isDestructive- iftrue, the submit button will be rendered using theButton.destructivevariant.withDividers- iftrue, a<Divider.horizontal />will be rendered between the child elements.onClickCancel- if provided, a "Cancel" button will be rendered. The callback function will be called when the button is clicked.onSubmit- aonSubmithandler for the form. If provided, this will be used instead of theonSubmitfunction from theformprop.