angular2-formbuilder

Reactive Forms - mark fields as touched

◇◆丶佛笑我妖孽 提交于 2019-11-28 19:06:26
I am having trouble finding out how to mark all form's fields as touched. The main problem is that if I do not touch fields and try to submit form - validation error in not shown up. I have placeholder for that piece of code in my controller. My idea is simple: user clicks submit button all fields marks as touched error formatter reruns and displays validation errors If anyone have other idea how to show errors on submit, without implementing new method - please share them. Thanks! My simplified form: <form class="form-horizontal" [formGroup]="form" (ngSubmit)="onSubmit(form.value)"> <input

What is the difference between formControlName and FormControl?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 17:19:43
I'm using ReactiveFormsModule of Angular2 to create a component that contains a form. Here is my code: foo.component.ts : constructor(fb: FormBuilder) { this.myForm = fb.group({ 'fullname': ['', Validators.required], 'gender': [] }); } foo.component.html (with [formControl] ): <div class="fields"> <div class="field"> <label>Fullname*</label> <input type="text" [formControl]="myForm.controls.fullname"/> </div> </div> <div class="inline fields"> <label for="gender">Gender</label> <div class="field"> <div class="ui radio checkbox"> <input type="radio" name="gender" checked="" tabindex="0" class=

formGroup expects a FormGroup instance

余生长醉 提交于 2019-11-27 14:16:54
I have an Angular 2 RC4 basic form example on Plunkr that appears to throw the following error (In Chrome DEV console) Here's the plunkr https://plnkr.co/edit/GtPDxw?p=preview Error: browser_adapter.ts:82 EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./App class App - inline template:1:7 ORIGINAL EXCEPTION: formGroup expects a FormGroup instance. Please pass one in. Example: <form [formGroup]="myFormGroup"> ORIGINAL STACKTRACE: Error: formGroup expects a FormGroup instance. Please pass one in. Example: <form [formGroup]="myFormGroup"> at new BaseException (https://npmcdn.com/

ngModel cannot be used to register form controls with a parent formGroup directive

六月ゝ 毕业季﹏ 提交于 2019-11-27 12:38:27
问题 After upgrading to RC5 we began getting this error: ngModel cannot be used to register form controls with a parent formGroup directive. Try using formGroup's partner directive "formControlName" instead. Example: <div [formGroup]="myGroup"> <input formControlName="firstName"> </div> In your class: this.myGroup = new FormGroup({ firstName: new FormControl() }); Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions: Example: <div [formGroup]=

Reactive Forms - mark fields as touched

安稳与你 提交于 2019-11-27 00:51:00
问题 I am having trouble finding out how to mark all form's fields as touched. The main problem is that if I do not touch fields and try to submit form - validation error in not shown up. I have placeholder for that piece of code in my controller. My idea is simple: user clicks submit button all fields marks as touched error formatter reruns and displays validation errors If anyone have other idea how to show errors on submit, without implementing new method - please share them. Thanks! My

What is the difference between formControlName and FormControl?

限于喜欢 提交于 2019-11-26 15:14:55
问题 I'm using ReactiveFormsModule of Angular2 to create a component that contains a form. Here is my code: foo.component.ts : constructor(fb: FormBuilder) { this.myForm = fb.group({ 'fullname': ['', Validators.required], 'gender': [] }); } foo.component.html (with [formControl] ): <div class="fields"> <div class="field"> <label>Fullname*</label> <input type="text" [formControl]="myForm.controls.fullname"/> </div> </div> <div class="inline fields"> <label for="gender">Gender</label> <div class=