angular-forms

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

Form Validation Angular 4

假如想象 提交于 2021-02-20 04:44:06
问题 So, I was attempting to use the following example: https://github.com/agiratech/angular4-reactive-form-exercise2/ However, when I implement it, and submit my form, no errors show anywhere on the screen. Below you will find all associated code that I can think of that relates. I'm looking for how to get the errors to show on the screen. I'm fairly new to Angular 4, so any help would be appreciated. pages.module.ts import ... import { FormsModule, ReactiveFormsModule } from '@angular/forms';

Iterate Array Inside of Array Angular 4

旧巷老猫 提交于 2021-02-19 06:13:48
问题 How can i iterate these arrays inside of arrays in select option in angular 4? I have this codes below. The problem that it produces several select option instead of a single select option. I want to iterate the acct_type_name only. How can i solve this? Thankssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss TS <ng-container *ngFor="let account of accounts"> <select type="text" class="form-control">

Iterate Array Inside of Array Angular 4

半城伤御伤魂 提交于 2021-02-19 06:13:28
问题 How can i iterate these arrays inside of arrays in select option in angular 4? I have this codes below. The problem that it produces several select option instead of a single select option. I want to iterate the acct_type_name only. How can i solve this? Thankssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss TS <ng-container *ngFor="let account of accounts"> <select type="text" class="form-control">

Iterate Array Inside of Array Angular 4

时间秒杀一切 提交于 2021-02-19 06:13:08
问题 How can i iterate these arrays inside of arrays in select option in angular 4? I have this codes below. The problem that it produces several select option instead of a single select option. I want to iterate the acct_type_name only. How can i solve this? Thankssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss TS <ng-container *ngFor="let account of accounts"> <select type="text" class="form-control">

Angular form validation: compare two fields in different form groups

人盡茶涼 提交于 2021-02-19 02:24:24
问题 I'm sorry if it's a duplicate of someone question. I didn't find a solution for my problem. Can anybody explain or give an example how to compare two fields in one form but in different form groups? Here is code snippet to see how my form and validator are look like: private createForm() { const testGroups = { groupOne: this.fb.group({ fieldOne: this.fb.control(null) }), groupsTwo: this.fb.group({ fieldTwo: this.fb.control(null, [this.matchValidator]) }) }; this.testForm = this.fb.group

What is the ideal way to sort a FormArray object in Angular 2+?

点点圈 提交于 2021-02-18 21:00:47
问题 I have a formArray which consist of multiple form groups. I need to sort the array dynamically based on a boolean field present in each of the form group in the array. The boolean field is a checkbox and at any given point of time only one checkbox can be checked (mimics radio button). So when a checkbox is clicked I need to sort the formArray based on the one that is selected. I know the documentation suggests not to mess with the AbstractControls[] present in the formArray, so what would be

Initializing Template Driven Form in Angular 7

柔情痞子 提交于 2021-02-11 06:59:42
问题 I'm looking to initialize certain form fields on a form and then call a function that has a if(this.form.valid) condition on it. on the ngOnInit function I have an API call that gets some basic info and fills it on the form: ngOnInit(){ this.apiService.getInfo(this.user.id).subscribe( userInfo => { this.formModel.fieldA = userInfo.A; this.formModel.fieldB = userInfo.B; this.formModel.fieldC = userInfo.C; this.doStuff(); } ); } However when calling this.doStuff() the form is invalid, even

Disabled controls from FormGroup (part of form custom form control) are excluded by .getRawValue() in parent

旧城冷巷雨未停 提交于 2021-02-07 09:25:23
问题 Having a component that implements ControlValueAccessor , with internal FormGroup to maintain the state of custom form control. When any field, that's part of that FormGroup is disabled, the field isn't visible when calling .getRawValue() method in parent form . By specification, .getRawValue() should return the raw object, including disabled fields. I've checked the code of .getRawValue() and here's what I found: getRawValue(): any { return this._reduceChildren( {}, (acc: {[k: string]:

Dynamic form validation in angular using eval

我的未来我决定 提交于 2021-02-06 14:23:50
问题 I have a dynamic form in Angular 7 and the fields, control-type, visibility, validations, everything comes from the database. I know that for dynamic forms if the validations coming from the database are built in Angular validations, it is much easier to do, but what I would like to do is build a custom validation for the array of validations coming for each control-type and using eval, evaluate it to true/false and based on that show the corresponding error messages. This link wont work in