Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[bug]: Combobox does not trigger validation in form (react-hook-form) #6698

Open
2 tasks done
Chipandcharge opened this issue Feb 20, 2025 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@Chipandcharge
Copy link

Chipandcharge commented Feb 20, 2025

Describe the bug

Combobox resets Input component validation state in form.
The same form is working when having Selects instead of comboboxes.

Affected component/components

Combobox, Input

How to reproduce

  1. Open the Dialog with "+ Test"
  2. Fill out all fields from top to bottom
  3. Form is not valid
  4. Focus on "test reason" input again
  5. Hit Tab to unfocus
  6. Form is valid

To narrow down the problem:

  1. Open the Dialog with "+ Test"
  2. Fill out all fields but the field test reason lastly
  3. Form is valid

Codesandbox/StackBlitz link

Preview:
https://9spz3k-3000.csb.app/

Code:
https://codesandbox.io/p/devbox/combobox-and-input-in-form-bug-9spz3k

Logs

System Info

Chromium, Linux

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@Chipandcharge Chipandcharge added the bug Something isn't working label Feb 20, 2025
@Chipandcharge Chipandcharge changed the title [bug]: [bug]: Combobox used in Form resets Input validation state Feb 20, 2025
@Chipandcharge Chipandcharge changed the title [bug]: Combobox used in Form resets Input validation state [bug]: Combobox does not trigger validation in form (react-hook-form) Feb 21, 2025
@Chipandcharge
Copy link
Author

UPDATE:
Selecting a item in the combobox does not trigger the validation for the field.

This can be fixed by manually triggering the validation with form.trigger() from useForm()

 <CommandItem
  key={approver.id}
  value={approver.name}
  onSelect={() => {
    form.setValue("approverId", approver.id, { shouldDirty: true })
    setOpenApprover(false)
    form.trigger("approverId")
  }}
>
  {approver.name}
    <Check
      className={cn(
        "ml-auto h-4 w-4",
        field.value === approver.id ? "opacity-100" : "opacity-0"
      )}
    />
</CommandItem>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant