angular-forms

Reactive Form Always Valid, Even When Not. Nested Children in Form

谁说胖子不能爱 提交于 2020-07-10 10:27:00
问题 I have seen a few StackOverflow issues with this question, but none of them seem to have proven answers that work. I am building a dynamically created Reactive Form Using Angular. StackBlitz here . The user has the option to add "groups" and "conditions" within the groups. Each group can be further nested using FormArrays. The form works as expected. Here are the main pieces of the form: AppComponent: The main Parent Component GroupControlComponent: The child of the parent. Takes care of all

angular 5 conditionally validate field based on another field's value

巧了我就是萌 提交于 2020-07-09 13:27:45
问题 How to conditionally validate a field based on another field's value? Here's what i've tried but it seems not to work this.PDform = _formbuilder.group({ [...] 'intlNumber': ['',this.nationality == 'Abroad' ? Validators.compose([Validators.pattern(this.phoneNumberExp), Validators.maxLength(14), Validators.minLength(11), Validators.required]) : Validators ] [...] }) 回答1: You can change the validators for a form control when the value of another form control changes by subscribing to the

angular 5 conditionally validate field based on another field's value

谁说我不能喝 提交于 2020-07-09 13:24:49
问题 How to conditionally validate a field based on another field's value? Here's what i've tried but it seems not to work this.PDform = _formbuilder.group({ [...] 'intlNumber': ['',this.nationality == 'Abroad' ? Validators.compose([Validators.pattern(this.phoneNumberExp), Validators.maxLength(14), Validators.minLength(11), Validators.required]) : Validators ] [...] }) 回答1: You can change the validators for a form control when the value of another form control changes by subscribing to the

angular 5 conditionally validate field based on another field's value

核能气质少年 提交于 2020-07-09 13:24:03
问题 How to conditionally validate a field based on another field's value? Here's what i've tried but it seems not to work this.PDform = _formbuilder.group({ [...] 'intlNumber': ['',this.nationality == 'Abroad' ? Validators.compose([Validators.pattern(this.phoneNumberExp), Validators.maxLength(14), Validators.minLength(11), Validators.required]) : Validators ] [...] }) 回答1: You can change the validators for a form control when the value of another form control changes by subscribing to the

FormArray without FormControls and just strings Angular 2

走远了吗. 提交于 2020-07-06 10:48:19
问题 I have two string arrays on my backend that I have to fill with either a single string or multiple strings. However they are not key value pairs. I am trying to push a string into one of the arrays but an running into the fact that I do not and cannot specify a control: value pair. my formArray looks like collections: new FormArray([]), my html to select the strings <md-select placeholder="Collection"> <md-option (click)="addCollectionId('one')" value="Local">Local</md-option> <md-option

Cannot Find Control with Path Using ngIf on Recursive Angular Form

自作多情 提交于 2020-06-27 16:47:29
问题 Here is the stackblitz for the code below. I am making a fairly complex deeply nested Angular form using FormArrays, and child components. For the most part, everything is working as expected. A group object contains a conjunctor , conditions[] , and groups[] . groups[] is a nested group that can be nested infinitely containing the same object. Currently, you have the option to "add group", "add nested group", "add condition", "delete group", and "delete condition" so that it makes a nested

Cannot Find Control with Path Using ngIf on Recursive Angular Form

大兔子大兔子 提交于 2020-06-27 16:47:12
问题 Here is the stackblitz for the code below. I am making a fairly complex deeply nested Angular form using FormArrays, and child components. For the most part, everything is working as expected. A group object contains a conjunctor , conditions[] , and groups[] . groups[] is a nested group that can be nested infinitely containing the same object. Currently, you have the option to "add group", "add nested group", "add condition", "delete group", and "delete condition" so that it makes a nested

Display and update FormGroup inside FormArray

流过昼夜 提交于 2020-06-17 13:14:25
问题 I am displaying a FormArray with an *ngFor. What i am trying to do is when i click on an item in the ngFor, to populate the with that items 'task' property. Additionally, when i type/update the contents of input, the original form is updated/patched. HTML: <form [formGroup]="myForm"> <div [id]="i" class="example-box" *ngFor="let item of myForm.get('items').controls; let i=index;" (click)="updateInput(item)"> {{item.value.task}} to be </div> <br> <br> <input formControlName="xxx" /> <br> <br>

Error: There are no form controls registered with this group yet. If you're using ngModel,you may want to check next tick (e.g. use setTimeout)

末鹿安然 提交于 2020-05-29 08:28:12
问题 I am using template driven form and am trying to set the value of the form elements based on some object properties, however i face the following on doing so. Also here is my code for the TD form and how i am trying to access it. .html file: <div class="row"> <div class="col-xs-12"> <form (ngSubmit)="onAddDevice(f)" #f="ngForm"> <div class="row"> <div class="col-sm-5 form-group"> <label for="name">Name</label> <input type="text" id="name" class="form-control" name="name" ngModel required> <

How to check if an input field is in focus in Angular 7 [duplicate]

隐身守侯 提交于 2020-04-18 07:19:08
问题 This question already has answers here : Detect Input Focus Using Angular 2+ (3 answers) Closed 8 months ago . I have a form and I want to know if any of the input fields in the form are focused or not? I read the ' NgForm ' documentation but didn't find anything related to ' focus '. I found touched but it doesn't satisfy needs. 回答1: You can use the focus and blur events, to track as fields gain or lose focus : <input (focus)="onFocus()" (blur)="onBlur()"> There are also javascript’s own :