reactive-forms

<textarea> default content disappears when adding formControlName the <textarea> element

こ雲淡風輕ζ 提交于 2019-12-23 12:28:18
问题 I'm trying to create a Reactive Form in Angular 4.0.2, which has a <textarea> field with default content, pulled from the database. The content in the <textarea> is showing without any issues, but when I add the formControlName="sectionContent" to the <textarea> element, the content from it disappears. <textarea formControlName="sectionContent ">{{ section.sectionContent }}</textarea > This issue is only happening with the <textarea> element, as I have other <input> fields in the form, but

Angular 2 - Reactive form Validation messages

陌路散爱 提交于 2019-12-23 07:26:45
问题 My objective is to put all my validation messages in component instead of html file I have a sign up page and below is the fields: public buildRegisterForm() { this.userForm = this.fb.group({ firstName: ['', [Validators.required, Validators.minLength(3)]], lastName: ['', [Validators.required, Validators.maxLength(50)]], emailGroup: this.fb.group({ email: ['', [Validators.required, Validators.pattern(this.emailPattern)]], retypeEmail: ['', Validators.required], }, { validator:

FormGroup containing Radio Buttons with an Angular FormArray

跟風遠走 提交于 2019-12-22 18:22:06
问题 I have the following code that dynamically adds a form group containing a title and two radio buttons to create a condition, effectively providing its title and whether or not it's an acceptable condition: export enum Acceptability { ACCEPTABLE, INACCEPTABLE } export interface Condition { title: string; acceptability: Acceptability; } export class AddCondition implements OnInit { form: FormGroup; ACCEPTABILITY = Acceptability; constructor(private fb: FormBuilder) {} ngOnInit() { // build the

Angular2 reactive form containing a list

爷,独闯天下 提交于 2019-12-21 04:10:39
问题 I am attempting to create a form for a user that will allow one to may phone numbers to be associated with the user. Is this possible with the current implementation of reactive forms? For example, I would want the below form to accept potentially many phone numbers. My front end implementation would show the phone number field, and would have a button that would allow for an additional phone number field to be added. userForm = new FormGroup({ firstName: new FormControl('', Validators

Dynamically add a set of fields to a reactive form

我怕爱的太早我们不能终老 提交于 2019-12-21 02:48:11
问题 I have 2 input fields: name and last name. I have 2 buttons: submit and 'add a person'. Clicking on 'add a person' should add a new set of fields (name and last name). How to achieve that? I found solutions how to add single input fields dynamically, but here I need to add a set My code now without 'add a person' functionality: import { FormControl, FormGroup, Validators } from '@angular/forms'; export class AppComponent implements OnInit { form: FormGroup; constructor(){} ngOnInit(){ this

Custom Controls with Reactive Forms

跟風遠走 提交于 2019-12-18 09:53:33
问题 I am using Angular 7, Angular Material controls with Reactive Forms. I created custom text (matInput type="text"), number (matInput type="number"), select (matSelect) controls with Angular Material with mat-form-field Here is the stackblitz for my example. I am trying to attach the custom form controls to reactive form and trying to fire any validations on the form group automatically. I am using ControlValueAccessor to achieve this, however my Select is not being identified as form control

Nested Headers and Table in Reactive Forms

我是研究僧i 提交于 2019-12-18 09:37:39
问题 I have several categories and each category has several materials/products. I have a problem since when i decided to delete a material/product on a category, I also delete a material/product in another category? How would able to fix this using reactive forms? How would i independently delete one material only and not another? This is the link to my code CODE LINK patchValues() { let rows = this.myForm.get('rows') as FormArray; this.orders.forEach(material => { material.materials.forEach(x =>

Allow Input Quantity Based On Available Quantity in Reactive Forms

走远了吗. 提交于 2019-12-14 03:08:49
问题 I need help in my problem since i need to input only the quantity based on the available quantity on my rows? How can i only submit the button if this requirement is met? How can i check for this? Here's the link LINK CODES initGroup() { let rows = this.addForm.get('rows') as FormArray; rows.push(this.fb.group({ ingredient_id: ['', Validators.required], qty_available: new FormControl({ value: '', disabled: true }, Validators.required), qty: ['', Validators.required] })) } 回答1: //when push the

How to do simple cross field validation in Angular 2 form to pass validation if one of the control in group has value?

梦想与她 提交于 2019-12-13 00:46:44
问题 This is so commonly used, there must be a simple way to approach this! So here is the situation. I have a form group: <ion-item-group formGroupName="alternativeRevenue"> <ion-item-divider color="primary" text-wrap sticky>Alternative revenue </ion-item-divider> <ion-item> <ion-label>Branded content</ion-label> <ion-toggle formControlName="brandedContent"></ion-toggle> </ion-item> <ion-item text-wrap *ngIf="businessFoundationsForm.get('alternativeRevenue.brandedContent').value"> <ion-label

reactive forms - on Submit, check if there is at least one change in the form and only then call the API

我们两清 提交于 2019-12-11 12:13:32
问题 What I want to achieve is something like this: When the user clicks on Submit button, in the background I need to compare if the state of the form has changed, by state I mean if there is at least one change in the form and only then call the API/Server to save information. If there are not any changes, just show a warning message to the user - "Hey you need to update something!"(console.log() is enough) *I also need to handle this case when the user changes something in the field1, for