Unverified Commit d13d1ba2 authored by Mary Lavanitha's avatar Mary Lavanitha Committed by GitHub

docs: improve form guide consistency and validation examples (#90361)

### What?
Small improvements to the Forms guide for consistency and clarity.

### Why?
Some examples didn’t fully match the recommendations in the guide (e.g.
HTML validation), and there was a minor inconsistency between
`event.target` and `event.currentTarget`. This update keeps the examples
aligned and easier to follow.

### How?
- Added `required` to relevant input examples  
- Standardized usage of `event.currentTarget`  
- Made minor wording refinements for clarity

---------
Co-authored-by: 's avatarvercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: 's avatarJoseph <joseph.chamochumbi@vercel.com>
parent e9c4f428
...@@ -67,7 +67,7 @@ export default function Page() { ...@@ -67,7 +67,7 @@ export default function Page() {
async function onSubmit(event) { async function onSubmit(event) {
event.preventDefault() event.preventDefault()
const formData = new FormData(event.target) const formData = new FormData(event.currentTarget)
const response = await fetch('/api/submit', { const response = await fetch('/api/submit', {
method: 'POST', method: 'POST',
body: formData, body: formData,
...@@ -171,7 +171,7 @@ export default function Page() { ...@@ -171,7 +171,7 @@ export default function Page() {
<div> <div>
{error && <div style={{ color: 'red' }}>{error}</div>} {error && <div style={{ color: 'red' }}>{error}</div>}
<form onSubmit={onSubmit}> <form onSubmit={onSubmit}>
<input type="text" name="name" /> <input type="text" name="name" required />
<button type="submit" disabled={isLoading}> <button type="submit" disabled={isLoading}>
{isLoading ? 'Loading...' : 'Submit'} {isLoading ? 'Loading...' : 'Submit'}
</button> </button>
...@@ -220,7 +220,7 @@ export default function Page() { ...@@ -220,7 +220,7 @@ export default function Page() {
<div> <div>
{error && <div style={{ color: 'red' }}>{error}</div>} {error && <div style={{ color: 'red' }}>{error}</div>}
<form onSubmit={onSubmit}> <form onSubmit={onSubmit}>
<input type="text" name="name" /> <input type="text" name="name" required />
<button type="submit" disabled={isLoading}> <button type="submit" disabled={isLoading}>
{isLoading ? 'Loading...' : 'Submit'} {isLoading ? 'Loading...' : 'Submit'}
</button> </button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment