angular2-form-validation

Angular reactive forms form-group validations are working only for any one row in Mat-table

ε祈祈猫儿з 提交于 2021-02-20 04:45:49
问题 I have Mat table with multiple rows, with add button ,on click of it, adds a new row . i want to add validations for all the rows ,right now my code below is taking a validation only for any one row. my component.html <form [formGroup]="auditUserValidation"> <mat-table [dataSource]="dataSource"> <ng-container matColumnDef="Audit"> <mat-header-cell *matHeaderCellDef> Name </mat-header-cell> <mat-cell *matCellDef="let element"> <mat-select formControlName="name" placeholder="Pls select"> <mat

how to trigger validation and get validation result after submit form action in Angular?

感情迁移 提交于 2020-01-25 06:47:08
问题 I have this formgroup: this.form = this.fb.group({ id: [], active: [true], name: [''], }); and this submit form function: onSubmit(submitForm: FormGroup) { this.submitForm.controls['name'].setValidators([MyValidators.unique(`name`, () => { return this.service.checkNameUnique(this.submitForm.value.name, this.labelFg.value.id); })]); } I didn't set validation to the form when initiating because this form will only be validated after I clicked the submit button. So I use the setValidators

Angular FormArray display validation errors

爷,独闯天下 提交于 2020-01-22 14:19:31
问题 I have Angular form that is built with help of FormBuilder. Form contains a FormArray which has as many fields as user wants. I've set validator for fields this.fb.array([this.fb.control('', Validators.required)]) and for each new push validator is the same. The problem is that I don't know how to access a specific field's isValid property since they are bound with FormControl via [formControlName]="index" . I've tried to do it that way, but it doesn't seem to work <div *ngIf="array.at(index)

Angular ng select required option

☆樱花仙子☆ 提交于 2019-12-11 01:13:40
问题 I cannot find out how to use the required option in ng-select. I have tried this: <ng-select #skills required [ngClass]="{ 'is-invalid': f.submitted && skills.invalid }" [items]="options" bindLabel="label" bindValue="value" [multiple]="true" placeholder="Select Skills" [(ngModel)]="registerUserData.skills" name="skills[]"> </ng-select> <div *ngIf="f.submitted && skills.invalid" class="invalid-feedback"> <div *ngIf="skills.errors.required"> Skills are required </div> </div> but no luck there..

How to show different validation messages for email validation in Angular2 using Validators class?

冷暖自知 提交于 2019-12-06 09:12:50
I am using FormGroup , FormBuilder and Validators class to validate a form in Angular2 app. This is how I am defining the required validation rules for email and password validation:- export class LoginComponent implements OnInit { loginFormGroup:FormGroup; adminLoginmodel = new Admin('', '', '', 'Emailsss','Passwordsss'); constructor( private route: ActivatedRoute, private router: Router, private _adminLogin: AdminLoginService, fb: FormBuilder ){ this.loginFormGroup = fb.group({ 'email' : [null, Validators.compose([Validators.required, Validators.email])], 'password': [null, Validators

at least one field is required in angular 4 forms

不羁岁月 提交于 2019-12-05 02:38:21
问题 I'm using angular 4 forms and I have some fields. and first_name, last_name and company are really important for me. I want to force the user to fill one of these 3 fields. how can I do it? here are .ts codes: this.contactForm = this.fb.group({ first_name: [null, Validators.compose([Validators.required])], last_name: [null, Validators.compose([Validators.required])], email: [null, Validators.compose([this.validateEmail])], company: [null], position: [null], }); an html: <form [formGroup]=

Angular FormArray display validation errors

别等时光非礼了梦想. 提交于 2019-12-04 06:27:37
I have Angular form that is built with help of FormBuilder. Form contains a FormArray which has as many fields as user wants. I've set validator for fields this.fb.array([this.fb.control('', Validators.required)]) and for each new push validator is the same. The problem is that I don't know how to access a specific field's isValid property since they are bound with FormControl via [formControlName]="index" . I've tried to do it that way, but it doesn't seem to work <div *ngIf="array.at(index).invalid" class="alert alert-danger p-2"> </div> Where array is a formArray.controls passed from a

at least one field is required in angular 4 forms

北城余情 提交于 2019-12-03 17:19:05
I'm using angular 4 forms and I have some fields. and first_name, last_name and company are really important for me. I want to force the user to fill one of these 3 fields. how can I do it? here are .ts codes: this.contactForm = this.fb.group({ first_name: [null, Validators.compose([Validators.required])], last_name: [null, Validators.compose([Validators.required])], email: [null, Validators.compose([this.validateEmail])], company: [null], position: [null], }); an html: <form [formGroup]="contactForm" fxLayout="column"> <md-input-container class="data_light"> <input class="data_font capital"