angular-reactive-forms

Angular 6 Follow up: [attr.disabled] in option value disables all entries

跟風遠走 提交于 2019-12-06 09:52:12
Topic: Angular 6, Reactive Form, DropDown Menu, Disable One Option: all instead of just the one intended value are disabled, even though the inspector says disabled=false. People were very kind to help me with my problem earlier: " Angular 6 Reactive Form - Select options: disable previously selected options " but they seemed to disappear after I hit a roadblock, hence my new question: Why are ALL option values disabled instead of just the one that is supposed to match the statement? [attr.disabled]="uplink2x === dropdown1Val" (even if I hardcode nic0 instead of dropdown1Val all options are

Setting errors on a FormGroup instance in Angular Reactive Forms not working as expected

£可爱£侵袭症+ 提交于 2019-12-06 08:07:27
I'm using Angular 4.4.3 reactive forms to implement custom validation for a group of controls in a form. The method AbstractControl.setErrors , according to docs updates the errors property of the AbstractControl, upon which it's invoked, updates the status of its parent, but not the parents errors property. I wanted to set the errors property on a FormGroup instance, so I use the setErrors inherited by the FormGroup. However, it does not update errors as expected. Following is my sample code: Trying it on FormControl instances, does update their errors as well as their parents' validity

Angular strongly typed reactive forms

时光总嘲笑我的痴心妄想 提交于 2019-12-06 07:25:36
问题 I'm looking to refactor a large set of components in my Angular project to have strongly typed FormGroups, FormArrays, and FormControls. I'm just looking for a good way to implement strongly typed reactive forms. Could anyone provide suggestions/recommendations from their own experiences? Thank you. EDIT: To clarify, by strongly typed I mean currently when I create a FormGroup or FormArray I have no way to specify the structure of the actual form inside it. When I pass this form around to

Angular reactive form based on model with validation

我只是一个虾纸丫 提交于 2019-12-06 04:11:03
is there a way to create a reactive form basing on an existing data model with all the validation magic. In the example below author passes whole new object into a formbuilder but what I want to achieve is elegant way to tell formbuilder what field is required or needs some other validation. https://malcoded.com/posts/angular-fundamentals-reactive-forms export class PersonalData { email: string = ''; mobile: string = ''; country: string = ''; } ... createFormGroupWithBuilderAndModel(formBuilder: FormBuilder) { return formBuilder.group({ personalData: formBuilder.group(new PersonalData()),

Angular material: mat-error not showing despite true methods

痞子三分冷 提交于 2019-12-06 04:01:24
问题 I have a confirm password formcontrol that I want to validate. I want to display my mat-error element when the password is not the same as the value in the confirm password input. For this I have a function called equalPasswords() . If the functions are the same then we receive true, if not, we receive false. <mat-form-field> <input matInput placeholder="Repeat password" [formControl]="password2" type="password"> <mat-error *ngIf="password2.invalid && password2.hasError('required')">Password

Forwarding formControlName to inner component in Angular

て烟熏妆下的殇ゞ 提交于 2019-12-06 02:04:57
I have one custom control component <some-input> that i wrapped to <ext-some-input> . SomeInput is encapsulated, has own API and supports reactive forms. ExtSomeInput is created as high-level wrapper over SomeInput . I have following html: <form [formGroup]="form"> <ext-some-input formControlName="name"> </form> and ExtSomeInput 's html: <some-input formControlName="_???_"></some-input> The question is how to forward formControlName to inner SomeInput component? I need to tie the form and inner formControl up. Is this possible? EDITED: I've created stackblitz project with this issue: here Your

How to implement auto save a reactive form in angular 4?

纵然是瞬间 提交于 2019-12-05 19:03:11
I want to auto save content in reactive form when form is valid without clicking save button. You will want to subscribe to the statusChanges() method of your FormGroup, and in that Observable you can determine whether the FormGroup is valid and then trigger a save event. import 'rxjs/add/operator/takeWhile'; import { FormBuilder, FormGroup } from '@angular/forms'; @Component({...}) export class MyComponent { private form: FormGroup; private alive: boolean; constructor(private formBuilder: FormBuilder) {} public ngOnInit(): void { this.alive = true; this.form = this.formBuilder.group({ // your

Buliding dropdown/select dynamically via reactive forms angular 6

巧了我就是萌 提交于 2019-12-05 18:41:51
I have multiple (any number) dropdowns on the form that i need to build dynamically. All these must have a value selected, so need to apply required validator. Sample json [ { "FeatureCaption": "Style", "SelectedValue": "shaker", "FeatureList": [ { "FeatureId": "CHOOSE", "FeatureName": "Choose", "IsSelected": true }, { "FeatureId": "shaker", "FeatureName": "Shaker", "IsSelected": false } ] }, { "FeatureCaption": "Material", "SelectedValue": "std", "FeatureList": [ { "FeatureId": "CHOOSE", "FeatureName": "Choose", "IsSelected": true }, { "FeatureId": "std", "FeatureName": "Standard",

How to validate disabled control using reactive forms (validation is not triggered)

久未见 提交于 2019-12-05 13:34:14
Let's say that I have this form structure: this.entryForm = this.formBuilder.group({ date: [{value:'' , disabled: true}, [Validators.required]], notes: [''], sum_credit: [{value:'', disabled: true }], sum_debit: [{value:'', disabled: true}], items: this.initItems() }); // set validation function to sum_credit this.entryForm.controls['sum_credit'].setValidators([CommonValidations.validateSomthing(...)]); The sum_credit is disabled because it's value is always calculated. Now I need to validate that the sum_credit is equaled to sum_debit , and I'm already doing that using validateSomthing

Unable to typing more than 1 character in input for FormArray within a FormArray for Reactive Forms

只愿长相守 提交于 2019-12-05 10:09:05
问题 I am thinking this could be a bug for Reactive Form. I would appreciate any help from more experienced Angular Experts. Symptom: Unable to key in more than 1 character in input at given time. Occurrence: When input is a FormArray within a FormArray I have included a Plunker link as below: https://embed.plnkr.co/zl2BQe/. //app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { ReactiveFormsModule } from '@angular/forms';