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

p-password not getting focused on a button click #15434

Closed
prshantsharma opened this issue May 2, 2024 · 2 comments
Closed

p-password not getting focused on a button click #15434

prshantsharma opened this issue May 2, 2024 · 2 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@prshantsharma
Copy link

Describe the bug

I'm using p-password component in my Angular application where I want to focus it on a button click if entered password is invalid.
I followed this below approach but didn't get the expected result:

 <p-password
      #newPasswordInput
      formControlName="newPassword"
      minLength="12"
      maxLength="20"
      [toggleMask]="true"
      placeholder="Enter new password"
      promptLabel="Choose a password"
      weakLabel="Too Simple"
      mediumLabel="Moderate"
      strongLabel="Strong"
      [mediumRegex]="MEDIUM_PASSWORD_REGEX"
      [strongRegex]="STRONG_PASSWORD_REGEX">
      <ng-template pTemplate="footer">
        <p-divider></p-divider>
        <p class="mt-2">Suggestions</p>
        <ul class="pl-2 ml-2 mt-0" style="line-height: 1.5">
          <li>Minimum 12 characters</li>
          <li>At least one lowercase</li>
          <li>At least one uppercase</li>
          <li>At least one numeric</li>
          <li>At least one special character $#^@$!%*,?&+-.</li>
        </ul>
      </ng-template>
 </p-password>

I keep a reference variable #newPasswordInput to p-password and accessing this using ViewChild() in .ts file as shown below:

if (!this.changePasswordForm.controls['newPassword'].valid) {
    this.newPasswordInput.nativeElement.focus();
    return this.toastrService.error(toasterMessage.invalidNewPassword, 'Error');
}

When I click submit button and if this condition is true, getting an error saying Cannot read properties of undefined (reading 'focus')

How can I achieve this or missing something? Please advice!

Environment

Using Angular

Reproducer

No response

Angular version

16.2

PrimeNG version

16.9.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.11

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@prshantsharma prshantsharma added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label May 2, 2024
@fsantanac
Copy link

The exact same thing happens to me

@mertsincan
Copy link
Member

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

3 participants