The formBuilder validator pattern seems to be malfunctioning

I am attempting to display a message when the password does not meet the formGroup pattern.

Here is how my FormGroup is initialized:

this.signupForm = fb.group({
  userName: ['', Validators.compose([Validators.required,Validators.pattern(/^\S*$/),Validators.pattern(`^[a-z0-9_-]{8,15}$`)])],
  image:[''],
  firstName: ['', Validators.required],
  lastName: ['', Validators.required],
  email: ['', Validators.compose([Validators.required, EmailValidator.isValid])],
  password: ['', Validators.compose([Validators.required,Validators.pattern(`^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$`)])],
  confirm: ['', Validators.required]
  }, {
  validator: PasswordValidation.MatchPassword
});

For the HTML part:

      <ion-item no-lines>
        <ion-label floating>
          <ion-icon name="lock"></ion-icon>Password</ion-label>
          <ion-input formControlName="password" type="password"></ion-input>
          <ion-icon  class="alert" *ngIf="signupForm.get('password').hasError('pattern')" name="alert-outline" item-right></ion-icon>
      </ion-item>

The issue I'm facing is that

signupForm.get('password').hasError('pattern')
always returns false!

signupForm.get('password').hasError('required')
and
signupForm.get('password').touched
are functioning correctly.

Could someone help me identify where the problem lies?

Answer №1

There is no icon with the name alert-outline:

https://i.stack.imgur.com/sT7hU.jpg

Perhaps you are actually looking for ios-alert-outline, in which case you should use...

<ion-icon *ngIf="..." md="ios-alert-outline" ios="ios-alert-outline" ..></ion-icon>

This should work without any issues... StackBlitz

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to compress an Array comprised of nested Arrays?

I am working on a function that takes in a specific type structure: type Input = [Array<string>, Array<number>, Array<boolean>]; It then transforms and outputs the data in this format: Array<[string, number, boolean]> This essenti ...

Angular - Expanding a d3 SVG element generated dynamically in the code

Welcome to my first question on this platform. If I make any mistakes, please forgive me. I am currently working on creating a simple SVG in Angular using the d3 library, but I am struggling to make it scale properly. After doing extensive research on SV ...

Generate an interactive sitemap.xml in ReactJS for each request made to http://example.com/sitemap.xml

I am working on a single-page application (SPA) using reactjs, and I have links in the format of http://example.com/blog/:id. I want to dynamically generate a sitemap for this site. While I'm aware that there are npm packages like react-router-sitema ...

Is the component not being initialized when navigating through the router, but only when the browser is refreshed?

I have noticed that when I navigate using the router, the data in the page does not update. However, if I refresh the browser, the updated data is shown in the router page. I am looking for a way to reload only the component without refreshing the entire ...

Adjusting ngClass dynamically as values change

Currently, I am facing a situation where I want to dynamically add a class to my view using ngClass based on changes in the output value. The output value is dependent on the response received from an API, and I am fetching data from the endpoint every sec ...

Obtain the content window using angularJS

I've been attempting to retrieve the content window of an iframe element. My approach in JQuery has been as follows: $('#loginframe')[0].contentWindow However, since I can't use JQuery in Angular, I've been trying to achieve thi ...

I am looking for a way to convert the date format from "yyyy-MM-dd" to "dd-MM-yyyy" in NestJs

I need help with changing the date format from "yyyy-MM-dd" to "dd-MM-yyyy". Currently, my entity code looks like this: @IsOptional() @ApiProperty({ example: '1999-12-12', nullable: true }) @Column({ type: 'date', nullable: true } ...

Angular does not support the functionality of having multiple material paginations within a single component

I am currently working on creating a component that contains two dataTables, each with a different dataSource. However, I am facing an issue where my Tables are not visible immediately after the component is loaded due to the *ngIf directive being used. Be ...

Is it possible to retrieve the second computed type in an overloaded method using TypeScript?

Looking for a solution to receive the second calculated type in an overload method using TypeScript type V1 = 'v1'; type V2 = 'v2'; type Versions = V1 | V2; async analyze(test: 'v1', data: number): Promise<void> ...

Presenting CSV data in a tabular format using Angular and TypeScript

I am facing an issue with uploading a CSV file. Even though the table adjusts to the size of the dataset, it appears as if the CSV file is empty. Could this be due to an error in my code or something specific about the CSV file itself? I'm still learn ...

The type 'function that takes in a CustomEvent and returns void' cannot be assigned to a parameter of type 'EventListenerOrEventListenerObject'

When I upgraded from TypeScript version 2.5.3 to 2.6.1, my custom event setup started giving me an error. window.addEventListener('OnRewards', (e: CustomEvent) => { // my code here }) [ts] Argument of type '(e: CustomEvent) => ...

Obtaining the identifier of a generic type parameter in Typescript

Is there a method in TypeScript to retrieve the name of a generic type parameter? Consider the following method: getName<T>(): string { .... implement using some operator or technique } You can use it like this: class MyClass{ } getName< ...

The recursive component is functional exclusively outside of its own scope

I'm facing an issue where my recursive component is not nesting itself properly. The problem arises when I try to use the Recursive component inside another Recursive component. Although the root is correctly inserted into the Recursive component fro ...

The problem with floating labels

I have been attempting to incorporate the floatlabels feature from floatlabels, but I am encountering difficulties in getting it to work properly. Here is the sequence of steps I have taken: Firstly, I include the JS file <script src="js/floatlabels. ...

Service that spans the entire application without relying on a service that is also used throughout the application

In continuation of my previous question, I am facing an issue with the No provider for ObservableDataService. I have an application-wide service named UploadedTemplatesService which must be a singleton. This service has one dependency - ObservableDataServ ...

Resolving Node.js Troubles: An Encounter with 'Module Not Found' Error

After generating a new application, I encountered an error while using the "ionic serve" command. [ng] The specified path cannot be found. [ng] internal/modules/cjs/loader.js:883 [ng] throw err; [ng] ^ [ng] Error: 'C:\Users\shane\Co ...

Angular's ExpressionChangedAfterItHasBeenCheckedError is a common issue that developers encounter

This message continues the discussion about a persistent issue I have been facing. Here is the link to the original thread on Stack Overflow: stackoverflow.com/questions/44596418/angular-throws-expressionchangedafterithasbeencheckederror-with-textarea Af ...

What is causing this issue in TypeScript version 4.8?

After updating to TypeScript 4.8 in VSCode, I have encountered an error in one of my React projects that was not present before. Strangely, this error does not prevent the code from compiling successfully when building the project. It's challenging to ...

Manufacturing TypeScript classes that are returned by a factory

Developed a custom library that generates classes based on input data and integrates them into a main class. To enhance code maintainability and readability, the logic for generating classes has been extracted into a separate file that exports a factory f ...

Unable to exclude folder while creating production build is not functioning as intended

I've got a directory full of simulated data in the "src/api/mock" folder, complete with ts and JSON files. I'm attempting to have Webpack skip over them during the production build process. I attempted to implement the following rule, but unfortu ...