NeedValidation.required, Validation.emailCheck

When creating a form in TypeScript, I encountered an issue:

private _createForm() {
    this.addForm = this._formBuilder.group({
        login: [ null, Validators.required ],
        name: [ null, Validators.required ],
        surname: [ null, Validators.required ],
        email: [ null, Validators.required, Validators.email]
    });
}

After implementing the form in HTML, the validation for the email field was not functioning as expected:

...
<forms-validation feedback="Niepoprawny adres email" [dataObj]="addForm ? addForm.controls.email : null" [inputRef]="email">
   <input type="text" name="email" formControlName="email" #email maxlength="{{maxlength}}" class="form-control" LayoutInput />
</forms-validation>
...

Although required validation is working correctly, the email validator is not functioning as intended.

Answer №1

It is important to organize validators within a sub array.

password: [null, [Validators.required, Validators.minLength(8)]]
                 ^                                       ^

Answer №2

You should consider implementing the pattern validator to address the issue with the email functionality.

email: ['', [Validators.required, Validators.pattern('^[A-Za-z0-9._%+-]+@[A-Za-z0-9._%+-]{2,}[.][A-Za-z]{2,}$')]]

Answer №3

Here is a different solution:

<input email type="text" name="email" formControlName="email" #email maxlength="{{maxlength}}" class="form-control" LayoutInput />

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

What steps are required to utilize NgbSortableHeader for sorting a bootstrap table through programming?

I have a bootstrap HTML table (operated by ng-bootstrap for Angular and utilized NgbdSortableHeader to arrange table columns by clicking on the column). When I click on an element, it sorts the column in ascending, descending, or ''(none) order. ...

Subclass method overloading in Typescript

Take a look at this example: class A { method(): void {} } class B extends A { method(a: number, b: string): void {} } An error occurs when trying to implement method() in class B. My goal is to achieve the following functionality: var b: B; b.met ...

Angular 6: Enable directive visibility for parent components via ng-content with Angular Material enhancements

I am currently working on developing custom Angular Material components using Angular 6. My attempt to set up something similar to the following has encountered some challenges: custom-input.component.html <custom-input-wrapper> <input m ...

Experiencing a 404 ERROR while attempting to submit an API POST request for a Hubspot form within a Next.js application

Currently, I am in the process of developing a Hubspot email submission form using nextjs and typescript. However, I am encountering a couple of errors that I need help with. The first error pertains to my 'response' constant, which is declared b ...

Steps for aligning the upper rectangular text in the center of the larger rectangular border

https://i.stack.imgur.com/7yr5V.png I was aware of a particular element in html that had text positioned in the upper left corner, but my knowledge didn't go beyond that. Should I be adjusting the translation on both the X and Y axes based on the par ...

Unlock the power of Env variables on both server and client components with Next.js! Learn how to seamlessly integrate these

In my Next.js app directory, I am facing the need to send emails using Nodemailer, which requires server-side components due to restrictions on client-side sending. Additionally, I am utilizing TypeScript in this project and encountering challenges when tr ...

Error in Angular2: Method this.http.post is invalid and cannot be executed

import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/catch'; // import 'rx ...

The ins and outs of Angular's type checking mechanisms

I have a few different scenarios on my mind. Imagine if I make an http call to fetch all movies from my php backend api. This is observable, so I need to subscribe to it. // Here's my service getAll() : Observable<Movie[]>{ this.http.get ...

Why does ng serve utilize "Hash: fec054139de85795"?

Shown below is the ng serve response: Lazy Chunk Details | File Names | Size src_app_features_main-overview_main-overview_module_ts.js | app-features-main-overview-main-overview-module ...

When the async keyword is added, the return type in Typescript can vary

This situation is really puzzling to me. I wrote a function to calculate the number of documents in a collection getDocCount(): Promise<number> { return MyModel.countDocuments({}); } Everything seemed fine. However, when I removed async since I ...

Transform Promise<any> into a designated type failure

Beginner inquiry concerning typescript/angular4+/ionic4. I have a service set up to make backend REST calls, and based on the response received, I need to store that data in local storage for future reference. However, I am encountering a type conversion e ...

Stop automatic variable updates in Angular

In Angular, variable x is assigned to variable y. Whenever variable x changes, y also gets changed. How can this behavior be prevented? ngOnInit() { this.editFunction() } editFunction(){ for (let i = 0; i < this.editingData["tags"].length; i ...

Choosing the most suitable stylesheet in Angular 8 when multiple CSS files are present

In my project, I have several CSS stylesheets for angular components. I am curious if there is a method to designate a preferred stylesheet when multiple sheets loaded by a component contain the same styles but with different values. ...

Having trouble downloading both an HTML file and a PDF file at the same time by clicking two separate buttons in an Angular 8 web API controller

I am encountering an issue with downloading files from my web application. I have two buttons - one for downloading a PDF file and another for downloading an HTML file. The problem arises when clicking on the link to download the HTML file first, as it do ...

Guide on exporting a submodule within a TypeScript package

My aspiration is to develop a Typescript library that emulates the structure of popular libraries like RxJS and Angular Material, which are divided into submodules. RxJS and Angular exhibit a way to import features using syntax like this: // RxJS import ...

When attempting to pass an array of objects to a child component, TypeScript raises an error regarding types

Hey everyone, I'm currently facing an issue while trying to pass an array of objects as props. Here's the content of my data.json file: [ { "category": "Reaction", "score": 80, "icon": " ...

Navigating the world of Typescript: mastering union types and handling diverse attributes

I am currently working on building a function that can accept two different types of input. type InputA = { name: string content: string color: string } type InputB = { name: string content: number } type Input = InputA | InputB As I try to impleme ...

retrieve document data from firestore using the service

Is there a way to get real-time data from a Firestore document using a service? According to Firebase's documentation, you can achieve this by following this link: https://firebase.google.com/docs/firestore/query-data/listen?hl=es#web-modular-api I ...

Exploring Angular Ag-Grid: Enhancing Row Expansion with a Simple Click

How can I increase the height of a particular row in Angular Ag Grid when clicked? I've edited the code in Stackbiz. Click here to see the edited data This is an example running from ag grid Tutorial Grid Tutorial Example ...

struggling to implement dynamic reactive forms with Angular

Currently, I am experimenting with building a dynamic reactive form using Angular. While I have successfully implemented the looping functionality, I am facing some challenges in displaying it the way I want. <form [formGroup]="registerForm" (ngSubmit) ...