angular2-formbuilder

Form Builder with hasError() for validation throws an error of ERROR TypeError: Cannot read property 'hasError' of undefined

↘锁芯ラ 提交于 2019-12-06 20:19:11
问题 Hi I am implementing a form in angular 2 using Form Builder in component.ts i have implemented my form using formGroup Below is My code public myForm: FormGroup; constructor(private authenticateservice: AuthenticateService, private _fb: FormBuilder ) { } ngOnInit() { this.myForm = this._fb.group({ address: [this.userDetails.address, [<any>Validators.required]], address2: ['', [<any>Validators.required]], city: ['', [<any>Validators.required]], company_address: ['', [<any>Validators.required]]

Validators same as other value in form

▼魔方 西西 提交于 2019-12-06 16:42:27
I am wondering if there is a Validator that compares two different values from the same form - lets say I have the following: this.loginForm = fb.group({ email: ["", Validators.required], password: ["", Validators.required], repeatPassword: ["", Validators.required] }); I found this in documentation, however it wasn't very helpful. Any ideas? Thierry Templier You need to assign a validator to a complete form group to implement this. Something like that: this.form = fb.group({ name: ['', Validators.required], email: ['', Validators.required] matchingPassword: fb.group({ password: ['',

endDate > startDate in angular material

蓝咒 提交于 2019-12-06 10:29:48
问题 I am building a component ( html , css , spec.ts , ts ) in angular in which I always want endDate > startDate . I have followed this link https://material.angular.io/components/datepicker/overview in order make multiple datepickers. This is the html which I have used for startDate and endDate. startDate: <div class="item item-1" fxFlex="50%" fxFlexOrder="1"> <mat-form-field> <input matInput [matDatepicker]="picker1" placeholder="{{'PORTAL.STARTDATE' | translate}}" type="text" formControlName=

How to show different validation messages for email validation in Angular2 using Validators class?

冷暖自知 提交于 2019-12-06 09:12:50
I am using FormGroup , FormBuilder and Validators class to validate a form in Angular2 app. This is how I am defining the required validation rules for email and password validation:- export class LoginComponent implements OnInit { loginFormGroup:FormGroup; adminLoginmodel = new Admin('', '', '', 'Emailsss','Passwordsss'); constructor( private route: ActivatedRoute, private router: Router, private _adminLogin: AdminLoginService, fb: FormBuilder ){ this.loginFormGroup = fb.group({ 'email' : [null, Validators.compose([Validators.required, Validators.email])], 'password': [null, Validators

How to populate a form with array of data in Angular2?

拈花ヽ惹草 提交于 2019-12-06 05:51:13
The SO question below helped me setup a formbuilder, proper validation, and a dynamic set of input fields from a formBuilder Array. How to assign and validate arrays to forms in Angular2 Note this solution code http://plnkr.co/edit/YoqdBEo0MihaxdhHH1FV?p=preview Everything works great on a new form, but I get stuck when trying to populate said form from the database. I'm using the following code and initialValue has multiple emails saved from this form in a previous transaction. All my other form fields work perfectly. I'm just not sure how to operate on an array. ngOnChanges(changes:

How to programmatically change pristine property in angular 2 form without ng-model

房东的猫 提交于 2019-12-05 19:30:04
I'm new in Angular 2 framework. I appreciate any help. I have usual component in angular 2: import {FORM_DIRECTIVES, FormBuilder, Validators} from 'angular2/common'; export class TestComponent { public values = ['value1', 'value2', 'value3', 'value4']; } Then I'm injecting FormBuilder into the constructor function: @Inject(FormBuilder) public fb HTML contain next markup: <input [(ngModel)]="formData.title" type="text" class="form-control" ngControl="title"> Title and description works great. But I've added bootstrap dropdown and it has no any form element . <div *ngFor="#value of values"

patch Value in a nested form control using angular2

六眼飞鱼酱① 提交于 2019-12-05 16:55:46
I need to set a value in a nested control in a FormBuiler and the model is the following: this.addAccForm = this.fb.group({ accid: ['', Validators.required], status: '', cyc: this.fb.array([ this.initCyc(), ]) }) initCyc() { return this.fb.group({ cycid: ['', Validators.required], name: ['', Validators.required], description: ['', Validators.required], status: ['', Validators.required], det: this.fb.group({ dcycid: ['', Validators.required], status: ['', Validators.required] }) }) I need to set a value cycid and also dcycid but I m stuck to it, I've tried to use the following line , but it

Angular 2 - Can't set form array value

倾然丶 夕夏残阳落幕 提交于 2019-12-05 16:08:46
问题 I get this error: There are no form controls registered with this array yet. If you're using ngModel, you may want to check next tick (e.g. use setTimeout). When using this code: public settingsForm: FormGroup = this.fb.group({ collaborators: this.fb.array([]), rsvp: this.fb.group({ latestDate: ['', [Validators.required]], latestTime: ['', [Validators.required]], guestLimit: ['', [Validators.required]], isRSVPOpen: false, isGuestPlusOne: false, isAutoApproveToGuestlist: false,

Validation on a list of checkboxes Angular 2

风流意气都作罢 提交于 2019-12-05 08:47:30
I have a list of business units that are rendered as checkboxes on a registration form along with a textbox field and am doing validation. <label for="inputFirstName" class="sr-only">First name</label> <input type="text" formControlName="firstName" class="form-control" placeholder="First name"> <div class="checkbox" *ngFor="let bu of businessUnits"> <label><input type="checkbox" #instance value="{{bu.BuName}}" (click)="getCheckBoxValue(instance.checked, bu.BuName)">{{bu.BuName}}</label> </div> The list of business units are retrieved from a database table and it is rendered when the form loads

Angular Form Control valueChanges not working

和自甴很熟 提交于 2019-12-05 02:45:15
I want to get one of my forms ("family") value if changed by subscribe but it seems something wrong, because I got nothing on my console's log. import { Component , AfterViewInit } from '@angular/core'; import {FormGroup,FormBuilder} from '@angular/forms'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'app-root', template: `<h1>Hello World!</h1> <form [formGroup]="frm1"> <input type="text" formControlName="name" > <input type="text" formControlName="family"> </form> `, }) export class AppComponent implements AfterViewInit{ frm1 : FormGroup; constructor( fb:FormBuilder){ this.frm1