You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, first off I'm a bit of an idiot. Sooo there may be a really simple explanation to this that I missed, never the less thanks in advance for however you help me if you do! :^)
Anyway, using NextJS V14 and everything I'm trying to make a Form inside of a Dialog. The issue is it doesn't submit at all when I click submit, but upon further testing, I've found that even an example provided by shadcn doesn't even work???
Anyway, here's my code:
"use client";importReactfrom"react";import{z}from"zod";import{CreateProjectSchema}from"@/schemas/index";// Ensure this is correctimport{zodResolver}from"@hookform/resolvers/zod";import{useForm}from"react-hook-form";importLinkfrom"next/link";import{Form,FormControl,FormDescription,FormField,FormItem,FormLabel,FormMessage,}from"@/components/ui/form";import{Dialog,DialogTrigger,DialogContent,DialogHeader,DialogDescription,DialogFooter,DialogTitle,}from"@/components/ui/dialog";import{Button}from"@/components/ui/button";import{Label}from"@/components/ui/label";import{Input}from"@/components/ui/input";import{Select,SelectTrigger,SelectValue,SelectContent,SelectItem,}from"@/components/ui/select";import{Textarea}from"@/components/ui/textarea";import{useToast}from"@/components/ui/use-toast";exportdefaultfunctionCreateProject(){const{ toast }=useToast();constform=useForm<z.infer<typeofCreateProjectSchema>>({resolver: zodResolver(CreateProjectSchema),defaultValues: {projectName: "",projectDomain: "other",projectOneLiner: "",projectDescription: "",projectLicense: "none",projectRepository: "",projectWebsite: "",},});functiononSubmit(values: z.infer<typeofCreateProjectSchema>){console.log("Form submitted with values:",values);}return(<Dialog><DialogTriggerasChild><Buttonvariant="default">Create Project</Button></DialogTrigger><DialogContentclassName="sm:max-w-[600px]"><DialogHeader><DialogTitle>Create New Project</DialogTitle><DialogDescription>
Fill out the details below to start your new open-source project.
</DialogDescription></DialogHeader><Form{...form}><formonSubmit={form.handleSubmit(onSubmit)}className="space-y-3"><divclassName="grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-4"><FormFieldcontrol={form.control}name="projectName"render={({ field })=>(<FormItem><FormLabel>Project Name</FormLabel><FormControl><Inputplaceholder="Enter project name"{...field}/></FormControl><FormDescription>
This is your project's public name.
</FormDescription><FormMessage/></FormItem>)}/><FormFieldcontrol={form.control}name="projectDomain"render={({ field })=>(<FormItem><FormLabel>Project Domain</FormLabel><FormControl><SelectonValueChange={field.onChange}defaultValue={field.value}><FormControl><SelectTrigger><SelectValueplaceholder="Select a project domain"/></SelectTrigger></FormControl><SelectContent><SelectItemvalue="ai/ml">AI / ML</SelectItem><SelectItemvalue="software">Software</SelectItem><SelectItemvalue="web">Web</SelectItem><SelectItemvalue="infrastructure">
Infrastructure
</SelectItem><SelectItemvalue="other">Other</SelectItem></SelectContent></Select></FormControl><FormDescription>
This is your project's domain / category.
</FormDescription><FormMessage/></FormItem>)}/></div><FormFieldcontrol={form.control}name="projectOneLiner"render={({ field })=>(<divclassName="space-y-2"><FormItem><LabelhtmlFor="oneliner">Project one-liner</Label><Textareaplaceholder="A place where people can build robots together."{...field}/><FormDescription>
A project one-liner is a brief yet effective description
of your project.
</FormDescription></FormItem></div>)}/><FormFieldcontrol={form.control}name="projectDescription"render={({ field })=>(<divclassName="space-y-2"><FormItem><LabelhtmlFor="description">Description</Label><Textareaid="description"placeholder="In this project, we aim to build a campus where people can collaborate on building robots together."rows={3}{...field}/><FormDescription>
This is your project's public description, feel free to be
as detailed as you want!
</FormDescription><FormMessage/></FormItem></div>)}/><div><FormFieldcontrol={form.control}name="projectLicense"render={({ field })=>(<FormItem><LabelhtmlFor="language">Project License</Label><SelectonValueChange={field.onChange}defaultValue={field.value}><SelectTrigger><SelectValueplaceholder="Select a project license"/></SelectTrigger><SelectContent><SelectItemvalue="mit">MIT License</SelectItem><SelectItemvalue="bsd3">
BSD 3-Clause "New" or "Revised" License
</SelectItem><SelectItemvalue="bsd2">
BSD 2-Clause "Simplified" License
</SelectItem><SelectItemvalue="isc">ISC License</SelectItem><SelectItemvalue="apache2">
Apache License 2.0
</SelectItem><SelectItemvalue="gnu3">
GNU General Public License v3
</SelectItem><SelectItemvalue="none">None</SelectItem></SelectContent></Select><FormDescription>
This is your project's license. Though at this time we
don't support many, here is more info on{" "}<spanclassName="underline"><Linkhref="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository#searching-github-by-license-type">
licenses
</Link></span>
.
</FormDescription><FormMessage/></FormItem>)}/></div><divclassName="grid grid-cols-2 gap-4"><FormFieldcontrol={form.control}name="projectRepository"render={({ field })=>(<FormItem><LabelhtmlFor="repo">Repository</Label><Inputid="repo"placeholder="Enter repository URL"{...field}/><FormDescription>
This is the link to your project's public repository.
</FormDescription><FormMessage/></FormItem>)}/><FormFieldcontrol={form.control}name="projectWebsite"render={({ field })=>(<FormItem><LabelhtmlFor="repo">Website</Label><Inputid="web"placeholder="Enter project's website URL"{...field}/><FormDescription>
This is the link to your project's public website.
</FormDescription><FormMessage/></FormItem>)}/></div><Buttontype="submit"className="space-y-reverse space-y-4">
Create Project
</Button></form></Form></DialogContent></Dialog>);}
Also here's my schema (in another file, yes it is imported correctly):
exportconstCreateProjectSchema=z.object({projectName: z.string().nonempty("Project name is required"),projectDomain: z.enum(["ai/ml","software","web","infrastructure","other",]),projectOneLiner: z.string().min(2).max(140).nonempty("Project one-liner is required"),projectDescription: z.string().nonempty("Project description is required"),projectLicense: z.enum(["mit","bsd3","bsd2","isc","apache2","gnu3","none",]),projectRepository: z.string().url().optional(),projectWebsite: z.string().url().optional(),});
And again, I probably missed something major lol, but I've been at this for hours and I'd really appreciate some help. Thanks in advance! :D
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, first off I'm a bit of an idiot. Sooo there may be a really simple explanation to this that I missed, never the less thanks in advance for however you help me if you do! :^)
Anyway, using NextJS V14 and everything I'm trying to make a Form inside of a Dialog. The issue is it doesn't submit at all when I click submit, but upon further testing, I've found that even an example provided by shadcn doesn't even work???
Anyway, here's my code:
Also here's my schema (in another file, yes it is imported correctly):
And again, I probably missed something major lol, but I've been at this for hours and I'd really appreciate some help. Thanks in advance! :D
ps: sorry for how much code is here.
Beta Was this translation helpful? Give feedback.
All reactions