shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
64.77k stars 3.69k forks source link

Input of type number is returning as string #3981

Open Kendaichi opened 1 month ago

Kendaichi commented 1 month ago

Describe the bug

Utilizing the Form Component of Shadcn, I noticed that the Input Components of type number are returning me string values.

Now I have a schema here from ZOD

likelihood_rating: z.number().int().min(1).max(5),

And this is my formField:

<FormField
                    control={form.control}
                    name="likelihood_rating"
                    render={({ field }) => (
                      <FormItem>
                        <FormLabel>Likelihood Rating</FormLabel>
                        <FormControl>
                          <Input
                            type="number"
                            placeholder="Likelihood Rating"
                            {...field}
                            autoComplete="likelihood_rating"
                          />
                        </FormControl>
                        <FormMessage className="text-end" />
                      </FormItem>
                    )}
                  />

So now because of validation I am getting this FormMessage being displayed

image

Is there anything I can do with this?

Affected component/components

Input

How to reproduce

  1. Create a Zod Validation, that receives a number value: likelihood_rating: z.number().int().min(1).max(5),

  2. Now create a const form utilizing the useForm:

    const form = useForm({
    resolver: zodResolver(registerSchema),
    defaultValues: {
      likelihood_rating: "",
      consequence_rating: "",
      rating_category: "",
    },
    });
    1. Lastly create a Form utilizing the Form component of shadcn:
      <FormField
                  control={form.control}
                  name="likelihood_rating"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>Likelihood Rating</FormLabel>
                      <FormControl>
                        <Input
                          type="number"
                          placeholder="Likelihood Rating"
                          {...field}
                          autoComplete="likelihood_rating"
                        />
                      </FormControl>
                      <FormMessage className="text-end" />
                    </FormItem>
                  )}
                />

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Windows 11, Browser(Brave), CodeEditor(VSCode)

Before submitting

yzqzy commented 2 weeks ago

This problem does exist. When can it be fixed?