angular-reactive-forms

Reactive form for each table row

时间秒杀一切 提交于 2019-11-29 09:36:47
问题 I'm using Angular 2 and I want to validate controls in each row separately. But I'm not getting any way to do that. I want it to be done using reactive forms only and not using template-driven approach. I want [formGroup] on each <tr> . Any help will be appreciated. Below is the structure of my code: <tbody *ngFor="let single of allTeamDetails" [ngClass]="{'alternate-row-color': $even}"> <tr> <td class="td-data first-column"> <input type="text" class="input-text form-control" [value]="single

Angular Material: Reseting reactiveform shows validation error

試著忘記壹切 提交于 2019-11-29 07:48:28
I am using angular5 reactivemodule to show a form in my application. I had also used required validator which will subsequently make the field in red color and show an error msg to the user. It is working as expected but when I reset the form using this.form.reset() the form shows me a validation error that the specific field is required. I also used form.markAsPristine() or form.markAsUntouched() to make it work but the problem persist after applying multiple combination of possible pairs. example.html <form [formGroup]="checkForm" (ngSubmit)="submitForm()"> <mat-form-field> <input matInput

Angular 2: Apply Validator.required validation on some condition

折月煮酒 提交于 2019-11-29 02:27:58
I have a angular 2 form wherein I have to make a field required on some condition like: description: ['', Validators.required] This description field will be required only on some type of a condition like: if(true){descReq = true}; How can I achieve this, please suggest. Thanks in advance! You can add or remove a validator based on the the value of another control on the form: testForm: FormGroup; constructor(private formBuilder: FormBuilder) { this.testForm = this.formBuilder.group({ condition: [''], description: [''] }); this.testForm.controls['condition'].valueChanges.subscribe(result => {

Angular2 Reactive Forms formControl for radio buttons

[亡魂溺海] 提交于 2019-11-29 00:58:49
I'm building a form in Angular with Reactive Forms. I'm using the FormBuilder to make a group of fields. For textboxes this works extremely well. But I can't find a formControl for radio buttons. How does this work? Should I use <input formControlName="gender" type="radio"> just like I use with text input's? Should I do <input formControlName="gender" type="radio"> just like I do with text input's? Yes. How does this work? Form control directives use a ControlValueAccessor directive to communicate with the native element. There are different types of ControlValueAccessors for each of the

Angular 7 ,Reactive Form slow response when has large data

左心房为你撑大大i 提交于 2019-11-28 20:50:55
I have a very complex and large data and I have to build a Reactive form around it in a component. I've developed the form. But when I type something in one of the input fields to edit the populated data, it responds extremely slowly in updating the value of that field. I tried using updateOn:'blur' and 'submit' but without any luck. My question is, what is best practice to handle the form with large data? Update : This is my StackBlitz . Note : I've created a very minimal version of my actual implementation and I have performance issues in the Reactive Form. So after about a day of playing

angular 6 warning for using formControlName and ngModel

本秂侑毒 提交于 2019-11-28 17:14:21
I recently upgraded the angular version to 6-rc. I got following warning It looks like you're using ngModel on the same form field as formControlName. Support for using the ngModel input property and ngModelChange event with reactive form directives has been deprecated in Angular v6 and will be removed in Angular v7 For more information on this, see our API docs here: https://angular.io/api/forms/FormControlName#use-with-ngmodel What does it say exactly? the link does not have any fragment for #use-with-ngmodel I guess I need to remove ngModel and use formGroup as my data binding object. If

Enable When Checkbox is Check in Reactive Forms

旧城冷巷雨未停 提交于 2019-11-28 14:18:16
I need help in making the rows enable only when the checkbox is check. The default rows should be disabled but when the checkbox is only check, that row will be enabled. Here's the link to my code LINK CODES patchValues() { let rows = this.myForm.get('rows') as FormArray; this.orders.forEach(material => { material.materials.forEach(x => { rows.push(this.fb.group({ checkbox_value: [null], material_id: new FormControl({value: x.id, disabled: true}, Validators.required), material_name: x.name, quantity: [null, Validators.required] })) }) }) } Have a look at the Demo & Src Stack Blitz, Fork

formGroup.get vs formGroup.controls in reactive form - Angular

空扰寡人 提交于 2019-11-28 07:28:43
Is there any preferred way when selecting validation using myForm.controls['name'].valid myForm.get('name').valid as both seems to be only syntactically different but achieving the same goal. <label>Name <input type="text" formControlName="name"> </label> <div class="alert" *ngIf="!myForm.controls['name'].valid && myForm.controls['name'].touched"> {{ titleAlert }} </div> Same as <div class="alert" *ngIf="!myForm.get('name').valid && myForm.get('name').touched"> {{ titleAlert }} </div> From what I checked in the code, get has this code: AbstractControl.prototype.get = function (path) { return

Add item in dynamic reactive form in Angular

帅比萌擦擦* 提交于 2019-11-28 05:17:32
问题 I am trying to build a nested reactive form in Angular 5. I am able to push items at one level, but unable to push item at second level. ngOnInit() { this.orderForm = this.formBuilder.group({ customerName: '', email: '', items: this.formBuilder.array([this.createItem()]) }); } createItem(): FormGroup { return this.formBuilder.group({ name: 'a', description: 'b', price: 'c', //subItems: this.formBuilder.array([this.createSubItem()]) }); } //createSubItem(): FormGroup { //return this

Angular Material: Reseting reactiveform shows validation error

北战南征 提交于 2019-11-27 18:45:42
问题 I am using angular5 reactivemodule to show a form in my application. I had also used required validator which will subsequently make the field in red color and show an error msg to the user. It is working as expected but when I reset the form using this.form.reset() the form shows me a validation error that the specific field is required. I also used form.markAsPristine() or form.markAsUntouched() to make it work but the problem persist after applying multiple combination of possible pairs.