mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* fix(form): use native as default validation behavior * docs(form): delete explicit validationBehavior=native * test(form): adjusted form test validation behaviors * chore(form): adjusted stories with forms * chore(changeset): changed form default validation behavior to native * chore(changeset): removed packages with only test changes * chore(changeset): change to patch * chore(changeset): update package name * refactor(docs): update package name * refactor(docs): update to heroui --------- Co-authored-by: աӄա <wingkwong.code@gmail.com>
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
import {Button, Form, Input} from "@heroui/react";
|
|
|
|
export default function App() {
|
|
const [submitted, setSubmitted] = React.useState(null);
|
|
|
|
const onSubmit = (e) => {
|
|
e.preventDefault();
|
|
const data = Object.fromEntries(new FormData(e.currentTarget));
|
|
|
|
setSubmitted(data);
|
|
};
|
|
|
|
return (
|
|
<Form className="w-full max-w-xs" onSubmit={onSubmit}>
|
|
<Input
|
|
isRequired
|
|
errorMessage={({validationDetails, validationErrors}) => {
|
|
if (validationDetails.typeMismatch) {
|
|
return "Please enter a valid email address";
|
|
}
|
|
|
|
return validationErrors;
|
|
}}
|
|
label="Email"
|
|
labelPlacement="outside"
|
|
name="email"
|
|
placeholder="Enter your email"
|
|
type="email"
|
|
/>
|
|
<Button color="primary" type="submit">
|
|
Submit
|
|
</Button>
|
|
{submitted && (
|
|
<div className="text-small text-default-500">
|
|
You submitted: <code>{JSON.stringify(submitted)}</code>
|
|
</div>
|
|
)}
|
|
</Form>
|
|
);
|
|
}
|