angular-validation

Inconsistent validation issue in Angular custom component

末鹿安然 提交于 2020-01-22 13:13:46
问题 To show a kind of real world example, let's say that we want to use the @angular/material's datepicker in our application. We want to use it on a lot of pages, so we want to make it very easy to add it to a form with the same configuration everywhere. To fulfill this need, we create a custom angular component around a <mat-datepicker> with ControlValueAccessor implementation to be able to use [(ngModel)] on it. We want to handle the typical validations in the component, but in the same time,

Angular Validators: Can I add styling to form elements based on their validators?

青春壹個敷衍的年華 提交于 2020-01-06 05:43:07
问题 I'm using Angular with Forms version 4.1.0 and Material version 2.0.0-beta.8. I have fields that need to be marked as required based on a configuration stored in a database table, so the specific fields that are required can change depending on that configuration and are not known at development time. I am dynamically setting Validators.required on my form controls based on that configuration, and that is all working fine (i.e. the appropriate fields are turning red if you leave them blank

TypeError: _co.nome is undefined in Angular5 Form Validation

落花浮王杯 提交于 2020-01-06 02:20:10
问题 I have the following problem when creating a simple form with validation in Angular. This is the error presented: ERROR TypeError: _co.nome is undefined Stack trace: View_EmpresaCadastroComponent_0/<@ng:///EmpresaModule/EmpresaCadastroComponent.ngfactory.js:306:9 debugUpdateDirectives@webpack-internal:///./node_modules/@angular/core/esm5/core.js:14871:12 checkAndUpdateView@webpack-internal:///./node_modules/@angular/core/esm5/core.js:14018:5 callViewAction@webpack-internal:///./node_modules/

Pre-populating and validating date in Angular 6 reactive form

情到浓时终转凉″ 提交于 2020-01-04 14:02:01
问题 All the rest of the fields are getting pre-populated except date for me. For testing purposes, i have hard coded the date as MM/DD/YYYY. From the DB, i'll get Date and Time, so i'll need to use the pipe to make it MM/DD/YYYY (am i correct about this?) component code this.projectForm = new FormGroup({ 'name': new FormControl(project.ProjectName, [Validators.required, Validators.minLength(3), Validators.maxLength(20)]), 'customerName': new FormControl(project.CustomerName, [Validators.required,

Pre-populating and validating date in Angular 6 reactive form

狂风中的少年 提交于 2020-01-04 14:01:24
问题 All the rest of the fields are getting pre-populated except date for me. For testing purposes, i have hard coded the date as MM/DD/YYYY. From the DB, i'll get Date and Time, so i'll need to use the pipe to make it MM/DD/YYYY (am i correct about this?) component code this.projectForm = new FormGroup({ 'name': new FormControl(project.ProjectName, [Validators.required, Validators.minLength(3), Validators.maxLength(20)]), 'customerName': new FormControl(project.CustomerName, [Validators.required,

How to differentiate multiple Validators.pattern

微笑、不失礼 提交于 2020-01-02 02:31:08
问题 I have an input where user needs to type a longitude. I want to be able to display different error message when user types NaN or Not-Precise-Enough value. I'm using FormControl.hasError('ValidatorsName') to get the errors with validation, but it seems like I cannot differentiate those patterns. Template: <mat-form-field class="form-field"> <input matInput placeholder="Logitude" [formControl]="longitude"> <mat-error *ngIf="longitude.hasError('pattern')"> Longitude must be <strong>a number<

How to Add a Validator dynamically to a FormControl in Angular 2

岁酱吖の 提交于 2019-12-31 09:59:58
问题 I am using ReactiveFormsModule and have defined all my form controls including simple validators such as Validators.required within a const configuration. I wanted to add a custom validator to one of those FormControls. I have currently added the custom validator as a function within this configuration, and it is working fine, but it does not belong here, it really needs to live within my component, but I'm not sure how I can just attach a custom validator manually after the FormBuilder has

How to Add a Validator dynamically to a FormControl in Angular 2

落花浮王杯 提交于 2019-12-31 09:55:20
问题 I am using ReactiveFormsModule and have defined all my form controls including simple validators such as Validators.required within a const configuration. I wanted to add a custom validator to one of those FormControls. I have currently added the custom validator as a function within this configuration, and it is working fine, but it does not belong here, it really needs to live within my component, but I'm not sure how I can just attach a custom validator manually after the FormBuilder has

How to Add a Validator dynamically to a FormControl in Angular 2

本小妞迷上赌 提交于 2019-12-31 09:53:28
问题 I am using ReactiveFormsModule and have defined all my form controls including simple validators such as Validators.required within a const configuration. I wanted to add a custom validator to one of those FormControls. I have currently added the custom validator as a function within this configuration, and it is working fine, but it does not belong here, it really needs to live within my component, but I'm not sure how I can just attach a custom validator manually after the FormBuilder has

How to Add a Validator dynamically to a FormControl in Angular 2

杀马特。学长 韩版系。学妹 提交于 2019-12-31 09:53:09
问题 I am using ReactiveFormsModule and have defined all my form controls including simple validators such as Validators.required within a const configuration. I wanted to add a custom validator to one of those FormControls. I have currently added the custom validator as a function within this configuration, and it is working fine, but it does not belong here, it really needs to live within my component, but I'm not sure how I can just attach a custom validator manually after the FormBuilder has