File size: 4,359 Bytes
b9fe2b4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { Button } from '@/components/ui/button';
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form';
import { RAGFlowSelect } from '@/components/ui/select';
import { FormSlider } from '@/components/ui/slider';
import { Textarea } from '@/components/ui/textarea';
const options = [
{ label: 'xx', value: 'xx' },
{ label: 'ii', value: 'ii' },
];
const groupOptions = [
{ label: 'scsdv', options },
{ label: 'thtyu', options: [{ label: 'jj', value: 'jj' }] },
];
const formSchema = z.object({
username: z.number().min(2, {
message: 'Username must be at least 2 characters.',
}),
a: z.number().min(2, {
message: 'Username must be at least 2 characters.',
}),
b: z.string().min(2, {
message: 'Username must be at least 2 characters.',
}),
c: z.number().min(2, {
message: 'Username must be at least 2 characters.',
}),
d: z.string().min(2, {
message: 'Username must be at least 2 characters.',
}),
});
export default function TestingForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
username: 0,
},
});
function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values);
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<FormSlider {...field}></FormSlider>
</FormControl>
<FormDescription>
This is your public display name.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="a"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<FormSlider {...field}></FormSlider>
</FormControl>
<FormDescription>
This is your public display name.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="b"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<RAGFlowSelect
value={field.value}
onChange={field.onChange}
FormControlComponent={FormControl}
options={groupOptions}
></RAGFlowSelect>
<FormDescription>
This is your public display name.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="c"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<FormSlider {...field}></FormSlider>
</FormControl>
<FormDescription>
This is your public display name.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="d"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Textarea
{...field}
className="bg-colors-background-inverse-weak"
></Textarea>
</FormControl>
<FormDescription>
This is your public display name.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<Button
variant={'tertiary'}
size={'sm'}
type="submit"
className="w-full"
>
Test
</Button>
</form>
</Form>
);
}
|