angular-reactive-forms

Update form with Validation not working until atleast one value is changed in the form field-Angular- ReactiveForms

两盒软妹~` 提交于 2019-12-13 08:56:03
问题 When working with put/update method the button is disabled until each and every field is touched and atleast on value in each field is changed. whereas post method is working perfectly fine. Employee.component.html <form fxLayout="column" [formGroup]="editForm" #f="ngForm" (ngSubmit)="onSubmit()" > <div class="input-row"> <mat-form-field fxFlex> <mat-label>Id</mat-label> <input readonly value="{{data.emp.id}}" matInput #id disabled formControlName="id" required /> </mat-form-field> </div>

Why Angular 4 FormGroup custom validator not working?

六眼飞鱼酱① 提交于 2019-12-13 03:48:56
问题 Trying to add custom validator formValidator() on a form group. Depending on some condition I am setting the errors {invalidData: true} . But when the condition is false setting errors to null. The control2 itself has required validator. If I set errors to null, it will also clear the required validator. Refer the below code, createReactiveForm(data: any) { const formGroup = new FormGroup({ 'control1': new FormControl(data.value1), 'control2': new FormControl(data.value2, [Validators.required

Angular reactive: Populating the select control of the edit form fails

血红的双手。 提交于 2019-12-13 03:46:48
问题 I am new to Angular and I have an edit form using Angular 4 reactive forms, trying to populate the select with department, the rule is the hospital is populated from the user.hospital, then a cascading dropdown department based on the hospital while the hospital is correctly displayed, the department fails.. in the console, the populated department is showing the departmentId correctly. edit component: form = new FormGroup({ hospital: new FormControl({ value: 'hospitalId', disabled: true },

Unique value validation in FormControl of FormArray

南笙酒味 提交于 2019-12-13 03:34:03
问题 I am developing Job form where user can enter his hobbies in the Job Form. I have applied required validation on hobbyName formcontrol, but how can I validate hobby name which should be unique if there is more than one hobby. Below is my ts code import { Component,OnInit } from '@angular/core'; import { FormGroup,FormArray,FormBuilder,Validators } from "@angular/forms" @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class

how to get selected value of dropdown in reactive form

对着背影说爱祢 提交于 2019-12-13 03:19:31
问题 I am trying to get the selected value of the dropdown on change event to be sent on reactive form submission. I have a very similar scenario working for radio based on the answer from how to get selected value of radio in reactive form Here's the code for dropdown <div class="row" *ngIf="question.controls.type.value === 'dropdown'"> <div class="col-md-12"> <div class="form-group__text select"> <label for="type">{{ question.controls.label.value }}</label> <br><br> <select name="value"

How to keep RxJs observable from completing on error?

≯℡__Kan透↙ 提交于 2019-12-13 02:58:02
问题 I have an angular reactive form that makes a simple GET request. If for example, I should get some sort of HTTP error. The observable todo$ has now completed I can no longer change my search options and click to retry searching. I've made a stackblitz demo, in the demo I've added my subscription inside an initializer and if there is an error on the stream I catch it. After I catch it, I call the initializer again. This works but seems like the wrong way to handle errors. I've set up the form

Getting issue in registering contorl with form in Angular Reactive forms

白昼怎懂夜的黑 提交于 2019-12-13 02:48:05
问题 I am working on Angular Reactive forms. Initially I have an formarray in formgroup. afterwards I push formgroup into formarray to add form control dynamically. I am getting an issue when binding these control using formControlName. I am getting this Error: Cannot find control with path: 'controlArray -> 0 -> value' here is my component class code: ngOnInit(){ this.reviewForm = this.fb.group({ 'controlArray': new FormArray([]) }); this.showDefaultForm(); } First I am getting data in formsDb,

Validate input Text field based on complex roles and character position

≯℡__Kan透↙ 提交于 2019-12-12 12:57:52
问题 Basically I am a beginner to Angular as well as java script. Here am trying to validate a Reactive form Text field with some conditions. Conditions are: min value length should 7 and max is 25 . Valid input could be Alphanumeric values along with ‘Asterisk (*)’ from wildcard characters. Though text field allows to enter other special characters but that input is considered as invalid. Asterisk( ) is allowed to give as input from 5th to 13th position , and everything else is considered as

How to Upload multiple files in Angular 6 with ADDMORE button?

南楼画角 提交于 2019-12-12 08:16:06
问题 Hello, Everone. I've been trying to Upload above(image) use case. I know it is very easy when we have a single file. but now the scenario is different it consists of an array of objects with the file. Now my question is how can I render the formdata object with the array of objects where each object consists of a file. For dynamic form, I used angular reactive forms. Can anyone please suggest me how can send whole data to the backed with the single click on save button. For backend I used

Editing a Form in Angular

泪湿孤枕 提交于 2019-12-11 22:57:25
问题 Please help!! I am finding it very difficult to edit a form. I working with reactive form and adding data to the form and sending to the database works very well. Now I want to query the data in the database so I can edit it and send it again. The data is gotten from the database in form of a json object, I have tried to assign it to a form Group variable so I can display the data in the form and send it but I get errors. I Have also tried displaying the data with the template driven form. It