Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Password: Submit with React Hook Form #3645

Closed
cbaum86 opened this issue Nov 15, 2022 · 4 comments · Fixed by #3650
Closed

Password: Submit with React Hook Form #3645

cbaum86 opened this issue Nov 15, 2022 · 4 comments · Fixed by #3650
Assignees
Labels
Component: Documentation Issue or pull request is related to Documentation
Milestone

Comments

@cbaum86
Copy link

cbaum86 commented Nov 15, 2022

Describe the bug

When using Password component with React Hook Form, on submit, if the password is the only field to fail validation then React Hook Form attempts to put a focus on the password field but cannot and throws an error.

Standard input text and password fields work as expected, as does a password input wrapped in a div as generated by Prime React.

Reproducer

https://codesandbox.io/s/blissful-butterfly-pc6xhk

PrimeReact version

8.7.2

React version

18.x

Language

ES6

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Create a react hook form with at least one PrimeReact Password component (form can have other fields/inputs too).
  2. Make sure the PrimeReact Password component has some kind of validation - for example, field is required.
  3. Fill in all fields, except for the PrimeReact Password (or otherwise make this field invalid)
  4. Submit the form to see e.focus / elm.focus error.

Expected behavior

With all other fields types, standard html text or password, PrimeReact InputText then when submitting the form, if there are errors the first field with an error is focused on.
I would expect that, if the PrimeReact Password component is the first invalid field then the form should focus on this field too.

@cbaum86 cbaum86 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 15, 2022
@cbaum86 cbaum86 changed the title Component: Title Component: Password Component on Submit with React Hook Form Nov 15, 2022
@melloware melloware changed the title Component: Password Component on Submit with React Hook Form Password: Submit with React Hook Form Nov 15, 2022
@melloware
Copy link
Member

I will investigate this.

@melloware
Copy link
Member

I fixed your Code Sandbox: https://codesandbox.io/s/white-glade-i26wqu?file=/src/App.js:4459-4626

The issue is Password has an inputRef the main ref points to the wrapper DIV of the password.

              <Password
                {...field}
                inputRef={field.ref}
                type="password"
                placeholder="password input"
              />

@melloware melloware added Component: Documentation Issue or pull request is related to Documentation and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 15, 2022
@melloware melloware self-assigned this Nov 15, 2022
@melloware melloware added this to the 8.7.3 milestone Nov 15, 2022
@hugomf
Copy link

hugomf commented Dec 21, 2022

could you please update your example code using this fix on the react-form-hook example? it took me a while to figure it out: https://www.primefaces.org/primereact/reacthookform/

@melloware
Copy link
Member

@hugomf I updated the showcase for the next major deployment with a Password React Hook Example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Documentation Issue or pull request is related to Documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants