File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed
playground/src/app/(demo)/form/modules Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,11 @@ export const DemoInput = memo(
1515 className = "flex w-full rounded-md border border-solid border-input bg-background file:border-0 file:bg-transparent file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50 h-8 px-2.5 text-sm file:py-1.25 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive"
1616 { ...rest }
1717 />
18- { touched && < span className = "text-red-500" > touched</ span > }
19- { validated && < span className = "text-red-500" > validated</ span > }
20- { validating && < span className = "text-red-500" > validating</ span > }
18+ < div className = 'flex gap-x-4' >
19+ { touched && < span className = "text-blue-400" > touched</ span > }
20+ { validated && < span className = "text-red-400" > validated</ span > }
21+ { validating && < span className = "text-yellow-400" > validating</ span > }
22+ </ div >
2123 </ >
2224 ) ;
2325 } ,
Original file line number Diff line number Diff line change @@ -10,14 +10,33 @@ import { showToastCode } from './toast';
1010
1111type Inputs = {
1212 age : number ;
13+ bio : string ;
14+ birthday : string ;
15+ favoriteColor : string ;
16+ nickname : string ;
17+ password : string ;
18+ password2 : string ;
19+ pin : string ;
20+ role : string ;
1321 username : string ;
22+ username2 : string ;
23+ website : string ;
24+ workEmail : string ;
1425} ;
1526
1627const Validate = ( ) => {
1728 const [ form ] = useForm < Inputs > ( ) ;
1829
1930 const errors = useFieldError ( form ) ;
2031
32+ function validateNickname ( ) {
33+ form . validateField ( 'nickname' ) ;
34+ }
35+
36+ function validateUsername2 ( ) {
37+ form . validateField ( 'username2' ) ;
38+ }
39+
2140 useEffect ( ( ) => {
2241 showToastCode ( 'all Errors' , errors ) ;
2342 } , [ errors ] ) ;
@@ -266,7 +285,21 @@ const Validate = () => {
266285 />
267286 </ FormField >
268287
269- < Button type = "submit" > Submit</ Button >
288+ < div className = "flex gap-x-4" >
289+ < Button
290+ type = "button"
291+ onClick = { validateNickname }
292+ >
293+ Validate Nickname
294+ </ Button >
295+ < Button
296+ type = "button"
297+ onClick = { validateUsername2 }
298+ >
299+ Validate Username2
300+ </ Button >
301+ < Button type = "submit" > Submit</ Button >
302+ </ div >
270303 </ Form >
271304 </ Card >
272305 ) ;
You can’t perform that action at this time.
0 commit comments