angular-validation

Reactive Form Using ControlValueAccessor for SubForm Show Errors on Submit

廉价感情. 提交于 2019-12-23 20:13:24
问题 I have a simple login page with a reactive form and subform component app-login-form that uses ControlValueAccessor , which is working, but I can't figure out how to display the errors in the subform. This is an example before I start creating more complex forms. When submitted I try to access the subform and markAllAsTouched , but when I'm watching the elements that the classes don't change. I made a quick StackBlitz to show what I'm doing. How do I get the error messages to show up when I

How to allow nested components to be tracked by their parent and get values from their parent in Angular?

依然范特西╮ 提交于 2019-12-21 05:32:10
问题 I have a series of forms (each managed by 1 component). There is a pattern of inputs in these forms (e.g. many of them require to allow input of an address) that I have to refactor into re-usable components as they are used in multiple forms and I don't want to duplicate neither their logic nor their templates. Each re-usable component would have to have its logic have its template containing input tags and no <form> tag have its client validation constraints possibly receive initial values

Angular 2 custom validator to check when either one of the two fields is required

一笑奈何 提交于 2019-12-21 04:43:25
问题 I am trying to implement a custom validator function to check either of the Phone numbers(Home Phone and Mobile) are entered or not. I want to show the error message on both the fields when they are both touched and not have the valid value, for some reason my code is not working as anticipated. Please help me with this piece. -Thanks! Here is the stackblitz link https://stackblitz.com/edit/angular-ve5ctu createFormGroup() { this.myForm = this.fb.group({ mobile : new FormControl('', [this

Custom Validator Control Quantity in Reactive Forms

对着背影说爱祢 提交于 2019-12-20 05:43:09
问题 I had a hard time implementing a custom validation in my reactive forms in Angular. I need to control the quantity. The quantity should not be more than the available quantity. The problem how can i get the total of all the quantity if each row has subrows. How will i able to compute the total of subrows and compare it to its parent row where the available quantity is found. Here's my code below. Here's also the link to my code PLEASE CLICK THIS LINK customValidator(campo1: string) { return

Angular2 Forms :Validations, ngControl, ngModel etc

强颜欢笑 提交于 2019-12-17 10:32:48
问题 Working on angular2 beta Forms . after alot of searching found nothing useful. hope here somebody help me. Basically i am bit confused how to use forms in angular2 in a proper manner (i.e using ngControl, ngFormControl etc). i have created one plnkr here http://plnkr.co/edit/fictP28Vqn74YqrwM1jW?p=preview here is my .html code:- <form class="form-horizontal" id='myForm' role="form" [ngFormModel]="CreateGroup"> <div class="col-md-7"> Name: <input type="text" id="name" placeholder="Name" class=

Angular2 Forms :Validations, ngControl, ngModel etc

混江龙づ霸主 提交于 2019-12-17 10:32:09
问题 Working on angular2 beta Forms . after alot of searching found nothing useful. hope here somebody help me. Basically i am bit confused how to use forms in angular2 in a proper manner (i.e using ngControl, ngFormControl etc). i have created one plnkr here http://plnkr.co/edit/fictP28Vqn74YqrwM1jW?p=preview here is my .html code:- <form class="form-horizontal" id='myForm' role="form" [ngFormModel]="CreateGroup"> <div class="col-md-7"> Name: <input type="text" id="name" placeholder="Name" class=

Custom Validator on reactive form for password and confirm password matching getting undefined parameters into Angular 4

可紊 提交于 2019-12-17 08:48:13
问题 I'm trying to implement a custom validator to check if the password and password confirm are equal. The problem is that the validator is getting undefined password and confirmedPassword parameters. How do I make this work. The function works cause if I change the condition to === instead of !== it throws the error correctly when the fields are the same. Does anyone know which is the error here? signup.component.html <div class="col-md-7 col-md-offset-1 col-sm-7"> <div class="block"> <div

Angular 4 validator to check 2 controls at the same time

假装没事ソ 提交于 2019-12-17 05:15:45
问题 I have a reactive form with 2 controls (port_start and port_end) that have the following requirements: Both must have a value Their values must be between 0 and 65535 port_start value must be less than port_end value This is what I tried so far: [...] this.formModel.addControl('port_start', new FormControl(object.port_start ? object.port_start : 0, [Validators.required, Validators.min(0), Validators.max(65535), this.minMaxValidator('port_start', 'port_end').bind(this)])); this.formModel

Angular 4 validator to check 2 controls at the same time

妖精的绣舞 提交于 2019-12-17 05:15:20
问题 I have a reactive form with 2 controls (port_start and port_end) that have the following requirements: Both must have a value Their values must be between 0 and 65535 port_start value must be less than port_end value This is what I tried so far: [...] this.formModel.addControl('port_start', new FormControl(object.port_start ? object.port_start : 0, [Validators.required, Validators.min(0), Validators.max(65535), this.minMaxValidator('port_start', 'port_end').bind(this)])); this.formModel

Why Angular 4 FormGroup custom validator not working?

六眼飞鱼酱① 提交于 2019-12-13 03:48:56
问题 Trying to add custom validator formValidator() on a form group. Depending on some condition I am setting the errors {invalidData: true} . But when the condition is false setting errors to null. The control2 itself has required validator. If I set errors to null, it will also clear the required validator. Refer the below code, createReactiveForm(data: any) { const formGroup = new FormGroup({ 'control1': new FormControl(data.value1), 'control2': new FormControl(data.value2, [Validators.required