angular2-forms

Cannot set initial form values into FormArray

南笙酒味 提交于 2021-02-19 23:55:18
问题 I have a reactive form that on cancel has to set again the initial form values into the formGroup. import { Map } from "immutable"; @Input() data: any; public ngOnInit() { if (this.data && this.data.controls) { this.group = this.fb.group({ isActive: [this.data.isActive], items: this.fb.array(this.buildFormArray(this.data.controlPerformers)), }); // Deep copy of the formGroup with ImmutableJs this.originalFormData = Map(this.group).toJS(); } } public buildFormArray(controllers:

Cannot set initial form values into FormArray

感情迁移 提交于 2021-02-19 23:54:27
问题 I have a reactive form that on cancel has to set again the initial form values into the formGroup. import { Map } from "immutable"; @Input() data: any; public ngOnInit() { if (this.data && this.data.controls) { this.group = this.fb.group({ isActive: [this.data.isActive], items: this.fb.array(this.buildFormArray(this.data.controlPerformers)), }); // Deep copy of the formGroup with ImmutableJs this.originalFormData = Map(this.group).toJS(); } } public buildFormArray(controllers:

Cannot set initial form values into FormArray

半城伤御伤魂 提交于 2021-02-19 23:50:31
问题 I have a reactive form that on cancel has to set again the initial form values into the formGroup. import { Map } from "immutable"; @Input() data: any; public ngOnInit() { if (this.data && this.data.controls) { this.group = this.fb.group({ isActive: [this.data.isActive], items: this.fb.array(this.buildFormArray(this.data.controlPerformers)), }); // Deep copy of the formGroup with ImmutableJs this.originalFormData = Map(this.group).toJS(); } } public buildFormArray(controllers:

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

Formbuilder setvalue() is not working as expected when used on dropdown selects

元气小坏坏 提交于 2021-02-18 14:07:31
问题 Angular 2,4 formbuilder setvalue() is not working as expected when used on dropdown selects. I have the following dropdown select that gets populated with Github organizations: <select name="org" formControlName="organizations"> <option *ngFor="let org of organizations" [ngValue]="org">{{org.organization.login}}</option> </select> Here is the javascript code that sets the Github organization that should be selected. this.pipelineForm = fb.group({ name:'', organizations:'', repos: '', branches

Formbuilder setvalue() is not working as expected when used on dropdown selects

流过昼夜 提交于 2021-02-18 14:02:49
问题 Angular 2,4 formbuilder setvalue() is not working as expected when used on dropdown selects. I have the following dropdown select that gets populated with Github organizations: <select name="org" formControlName="organizations"> <option *ngFor="let org of organizations" [ngValue]="org">{{org.organization.login}}</option> </select> Here is the javascript code that sets the Github organization that should be selected. this.pipelineForm = fb.group({ name:'', organizations:'', repos: '', branches

what is the proper way to dynamically mark a field as required using Angular 2 Forms?

亡梦爱人 提交于 2021-02-07 13:16:58
问题 Using Angular 2 (2.0.0), what is the recommended way to dynamically mark a field as required, using Angular Forms? In all of their examples, the required attribute is just added like: <input type="text" class="form-control" id="name" required> What if the model I'm binding to has an IsRequired property, that will be true/false? If I use something like: <input [(ngModel)]="field.Value" type="text" value="{{field.Value}}" [attr.required]="field.IsRequired"/> That renders on the page like (note

what is the proper way to dynamically mark a field as required using Angular 2 Forms?

半世苍凉 提交于 2021-02-07 13:16:43
问题 Using Angular 2 (2.0.0), what is the recommended way to dynamically mark a field as required, using Angular Forms? In all of their examples, the required attribute is just added like: <input type="text" class="form-control" id="name" required> What if the model I'm binding to has an IsRequired property, that will be true/false? If I use something like: <input [(ngModel)]="field.Value" type="text" value="{{field.Value}}" [attr.required]="field.IsRequired"/> That renders on the page like (note

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]:

Angular: Template Driven Forms - Enable submit button if at least one field is entered

爷,独闯天下 提交于 2021-01-28 06:12:26
问题 I have a simple form that has a set of fields and I want to enable the submit button if at least one field has been entered. I don't wanna use a Model Driven Form as I feel it's a overkill, given the scenario. What is the simplest way to check if at least one field is not empty in Template Driven Forms? 回答1: You can work with ngModel and ngModelChange . In your html: <input type="text" class="form-control" [(ngModel)]="yourvalue" (ngModelChange)="valueChanged()" /> In your component: private