angular-reactive-forms

Angular 7 : How do I submit file/image along with my reactive form?

假装没事ソ 提交于 2019-12-11 05:33:02
问题 I have created simple reactive form with text input and when form is being submitted I want to pass along image from file input. Every time I google I get tutorials, where they show me how I can upload file, but it is being done without other input field. I understand how to do that, what I don't understand how to submit both my form along with file input in one submission. In my scenario, am I not supposed to user reactive forms and instead simple new FormData() and append every input into

Angular reactive form [disabled] attribute doesn't work for text field based on validity of another text field

感情迁移 提交于 2019-12-11 05:28:15
问题 below is the code snippet for angular reactive form field. The button stays disable until I valid input in mobile field but the same doesn't work for text field. I want second input text field to be disabled until I enter a valid input to mobile field. <div id="mobile_verification"> <input class="form-control" id="mobile" formControlName="mobile" placeholder="Mobile no." maxlength="10"> <input class="form-control" id="otp" [disabled]= "!contactForm.controls['mobile'].valid" formControlName=

Angular 6 Reactive Form - Select options: disable previously selected options

老子叫甜甜 提交于 2019-12-11 05:19:41
问题 I have 3 dropdown menus that must have unique values (I am assigning network adapters here), so if one nic is selected in dropdown 1, it must be disabled in dropdowns 2 and 3. I have found this answer and a few other's, but I can't get them to work. component.ts nicAdapters: any[] = ['nic0','nic1','nic2','nic3','nic4','nic5','nic6','nic7','nic8','nic9','nic10'] this.inputForm = this.fb.group({ upLinks: this.fb.group ({ NumberUplinks: ['2'], uplinksMgmt: this.fb.group ({ uplink1: ['nic0'],

Extending FormControlDirective in Angular 2+

限于喜欢 提交于 2019-12-11 04:58:00
问题 I'm looking at this question, trying to figure out how to extend FormControlDirective: Attempting to extend FormControlDirective to implement my own FormControl directive results in faulty binding. There is an answer, but I'm not sure what is meant by: The formControl \ formControlName selectors appear in one more place - the value accessor. In order your directive to work you should implement all default value accessors for the hybridFormControl directive ( following the pattern for the

Set Value Not Less Than 0 In FormArray Reactive Forms

二次信任 提交于 2019-12-11 04:29:14
问题 I have successfully implemented the value in the input field to not less than 1 in the "quantityControl" formControlName. However my problem is when on the formArray. How can i set that to not than less than 0 or should not be a negative number? Here's the code below and the link to my stackblitz CODE LINK this.inquiryForm.get('quantityControl').valueChanges.pipe( filter(quantity => quantity < 1) ).subscribe(value => { console.log(value); this.inquiryForm.get('quantityControl').setValue(1); }

FormControlName not working with ion-radio

泪湿孤枕 提交于 2019-12-11 04:14:42
问题 New: So I can get it to work withou a radio-group or withouth the right bindings. I can't get it to work with both. This is allowed: <div *ngFor="let column of row.controls.columns.controls; let j = index"> <ion-list radio-group [formControlName]="'col'+j"> <ion-radio></ion-radio> </ion-list> </div> But then I don't have a list with a radio-group, it doesn't matter what I change it will always break. If I move the list outside it breaks, move the formControlName it breaks. I really don't know

How to set value on object on formbuilder inside another - Typescript

筅森魡賤 提交于 2019-12-11 02:54:58
问题 I want to access an existing formBuilder and set value of a specific object. The problem is that is not a normal formbuilder. It is a formbuilder inside another. code: formBuilder.group({ nasty: formBuilder.group({ myobject: ['', []], })}); How can I set value on myobject? 回答1: This is just a FormGroup within a FormGroup . You could just patchValue whole form object. this.form.patchValue({ nasty: { myobject: 'POPULATED' }}) Or you could target specific one. this.form.get('nasty.something')

how to get selected value of radio in reactive form

和自甴很熟 提交于 2019-12-11 00:58:59
问题 I am trying to get the selectedValue of the radio button and pass it as true with the radio text. selectedValue to be sent as true if Choice 1 is selected else false. And selectedValue to be sent as true if Choice 2 is selected, else false. I could not set it to true. Was wondering if anyone has done this before? https://stackblitz.com/edit/angular-xfrezb 回答1: First of all, always include the relevant code in your question as code blocks, since links tend to die over time... But as for your

How to get values of reactive form inputs in Angular?

这一生的挚爱 提交于 2019-12-11 00:47:03
问题 I need to grab reactive form inputs email and password and pass them to my function which calls register service method to register new user in firebase using email. Unfortunately, in chrome console after form submission I get RegisterComponent.html:2 ERROR ReferenceError: email is not defined My code looks like this now: register.component.ts export class RegisterComponent { form: FormGroup; constructor(fb: FormBuilder, private authService: AuthService) { this.form = fb.group({ email:[''

Uncheck all boxes in form group in angular 7

泄露秘密 提交于 2019-12-11 00:20:02
问题 I need to have one check box in a form group that unchecks all checkboxes in the same form group as well as keep my validation. In my TS file i have: initForm() { this.financialSectionSix = this.formBuilder.group({ medicaidOrSssi: [false], snap: [false], freeOrReducedPriceLunch: [false], tanf: [false], wic: [false], noneOfTheAbove: [false] }); } In my HTML I have this: <div [hidden]="selectedSectionGroup.sectionSix" class="tab-pane fade show active" id="{{financialSectionEnum.SECTION_SIX}}"