Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

Angular, SCSS

angular, sass/scss
Marissa Huysentruyt•165
@marissahuysentruyt
A solution to the Intro component with sign-up form challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I am struggling with the very last password validation. Here's my TS for the password validator:

password: this.formBuilder.control('',
    Validators.compose([
      Validators.required,
      Validators.minLength(8),
      Validators.maxLength(20),
    ])
)

I have 2 *ngIf statements: one to display if the password is left blank, and another to display if the password isn't within the range of the minLength and maxLength. I can only get the blank password *ngIf to work, while the minLength/maxLength won't work 😵‍💫 I cannot get the minLength or maxLength Angular validators to catch the password input, and display the accompanying message. Any thoughts on what I'm missing? Do I need an additional conditional beside having errors in minLength/maxLength & the input being touched/dirty?

<label for="password" name="password">
    <input required name="password" type="password" placeholder="Password" id="password" formControlName="password">
    <div class="error" *ngIf="signUpForm.get('password')!.touched && signUpForm.get('password')!.pristine">
        <img src="../../assets/icon-error.svg" alt="Error!"> 
        <span>Password cannot be empty</span>
    </div> 
    <div class="error" *ngIf="(signUpForm.get('password')!.hasError('minLength') || signUpForm.get('password')!.hasError('maxLength')) && (signUpForm.get('password')!.dirty || signUpForm.get('password')!.touched)">
        <img src="../../assets/icon-error.svg" alt="Error!"> 
        <span>Password must be between 8 and 20 characters.</span>
    </div> 
</label>
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Marissa Huysentruyt's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License