angular-reactive-forms

Refer to FormBuilder Members in a Strongly Type safe way, instead of strings in Angular 8

别来无恙 提交于 2020-01-16 08:40:28
问题 Is there a way to refer to Formbuilder members names in a strongly type fashion? If form builder names change, then the get functions below will not notice, and not display any compilation error. This can create issues in program functionality. Need to refer to formbuilder control members in a clean way. { this.customerForm = this.formBuilder.group({ 'firstName': [null, [Validators.required,Validators.maxLength(50)]], 'phoneNumber': [null, [Validators.required,Validators.maxLength(50)]],

Reactive Form Array - Avoid Validation Error when push new elements

一个人想着一个人 提交于 2020-01-16 08:36:13
问题 I have a form group which is composed by a single form array: ngOnInit() { this.deviceDetailsFormGroup = this._formBuilder.group({ deviceDetails: this._formBuilder.array([ this.buildDeviceDetailsForm() ]) }); } Each control in the Form Array has required validators: buildDeviceDetailsForm(): FormGroup { return this._formBuilder.group({ ipAddressCtrl: [ "", [Validators.pattern(ipaddressPattern), Validators.required] ], hostnameCtrl: [ "", [ Validators.required, Validators.maxLength(30),

how to bind auto-complete selected value to form Control Name

ⅰ亾dé卋堺 提交于 2020-01-16 08:20:13
问题 I'm having an Angular(6) reactive form with a (prime-ng) autocomplete control. I'm managing to populate it correctly with values (of streets), but I'm missing something when trying to bind the streetID (and not street name) to the form control. I tried to use the value attribute, but it still didn't fixed it. See my Html code: <div class="form-group"> <label>Street <p-autoComplete formControlName="StreetID" [dropdown]="true" [suggestions]="autoCompleteStreetsNames" (completeMethod)=

Angular Iterate over Reactive Form Controls and Subchildren etc

强颜欢笑 提交于 2020-01-15 09:19:47
问题 I need to iterate through all controls in Formbuilder, and children formbuilders to clear validators and updateValueAndValidity. How can I update answer from here to do so ? Angular 2: Iterate over reactive form controls Object.keys(this.form.controls).forEach(key => { this.form.controls[key].clearValidators(); this.form.controls[key].updateValueAndValidity(); }); This form here has formbuilders within formbuilders, etc. The answer above only affects top level children, not subchildren, etc

Angular Iterate over Reactive Form Controls and Subchildren etc

拜拜、爱过 提交于 2020-01-15 09:19:09
问题 I need to iterate through all controls in Formbuilder, and children formbuilders to clear validators and updateValueAndValidity. How can I update answer from here to do so ? Angular 2: Iterate over reactive form controls Object.keys(this.form.controls).forEach(key => { this.form.controls[key].clearValidators(); this.form.controls[key].updateValueAndValidity(); }); This form here has formbuilders within formbuilders, etc. The answer above only affects top level children, not subchildren, etc

Passing formControlName into Angular component

倖福魔咒の 提交于 2020-01-15 07:47:27
问题 I have a reactive form. The setup is similar to this: myForm: FormGroup; this.myForm= new FormGroup({ name: new FormControl("", [Validators.required, Validators.maxLength(15), Validators.pattern('...')]), ... }); I use this on my form like this: <input type="text" formControlName="name" /> <div *ngIf="name.errors?.required"> Name is required </div> <div *ngIf="name.errors?.maxlength"> Name must be {{ name.errors.maxlength.requiredLength }} characters </div> <div *ngIf="name.errors?.pattern">

Add checkbox dynamically using angular 2

心不动则不痛 提交于 2020-01-14 04:46:27
问题 I am new to angular and currently using angular 5 i want to add check box and drop down list on click event() using Reactive form control. Please suggest a solution. 回答1: Your html template should look something like below: <div formArrayName="items" *ngFor="let item of items.controls; let i=index"> <div [formGroupName]="i" class="well"> <input type="checkbox" formControlName="isChecked" /> </div> <div *ngIf="isChecked.invalid && (isChecked.dirty || isChecked.touched)" class="alert alert

Angular 2+ material mat-chip-list formArray validation

[亡魂溺海] 提交于 2020-01-13 02:41:49
问题 How do I validate that a mat-chip has been added to the mat-chip-list . I am using ReactiveForms. I have tried with the required validator. The value can be a list of names, so I need to make sure that there is atleast 1 name in my list of names before I can submit the form. If the list is empty then mat-error should display the error message. Using the required validator makes the form invalid, regardless of adding names to the list. EDIT: Reactive Forms I have tried to make a custom

Angular 2+ material mat-chip-list formArray validation

霸气de小男生 提交于 2020-01-13 02:41:09
问题 How do I validate that a mat-chip has been added to the mat-chip-list . I am using ReactiveForms. I have tried with the required validator. The value can be a list of names, so I need to make sure that there is atleast 1 name in my list of names before I can submit the form. If the list is empty then mat-error should display the error message. Using the required validator makes the form invalid, regardless of adding names to the list. EDIT: Reactive Forms I have tried to make a custom

Custom Component MdDatePicker used in reactive Form

别来无恙 提交于 2020-01-11 13:15:18
问题 I am trying to create a custom component to be used in a angular formGroup. Here's is how I want to use this custom component: <form [formGroup]="form"> ... <app-date-picker formControlName="dateStart" [isConsultation]="isConsultation" [label]="'Du'" [(ngModel)]="agenda.datDeb"> </app-date-picker> ... </form> Problem : In the main component (containing this form), The model doesn't get updated when the value changes in my custom component, which is involving a MdDatePicker. Though I am using