Topic: mdb-date-picker doesn't work with formControlName
itay pro asked 6 years ago
Arkadiusz Idzikowski staff answered 6 years ago
import { Component, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; @Component({ selector:'app-root', templateUrl:'./app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { form:FormGroup; submit() { console.log(this.form); } ngOnInit() { this.form=newFormGroup({ sDate:newFormControl() }); } }
itay pro commented 6 years ago
I removed [(ngModel)]=”model” and placed the picker inside a working reactive form Error is: ERROR Error: No value accessor for form control with path: 'type -> sDate' Code is: mdb-date-picker [options]="myDatePickerOptions" formControlName="sDate" [placeholder]="'Selected date'"></mdb-date-pickerArkadiusz Idzikowski staff commented 6 years ago
Dear mdb2, Did you add 'sDate' as newFormControl of FormGroup in your ts file (the last lines of code from my example) and ReactiveFormsModule? Please provide an example of your typescript code so I can try to recreate this problem. Best, Arekitay pro commented 6 years ago
Yes, type.sDate exists in the form and the form is reactive. It is a part of a big form so it is difficult for me to share Since 'type' is the name of a form group, I tried to elevate the control to be directly under form but same results. I also tried to replace the date picker with an input and it works: input type="text" readonly formControlName="sDate" class="form-control" [mdbValidate]="false" mdbInputDirective Can you please point me to your documentation where there is an example of mdb-date-picker using formControl ?Arkadiusz Idzikowski staff commented 6 years ago
Dear mdb2, Did you try to use my example ts code with the html code you added to the previous post? Does the console show any errors in this case? Using this example I managed to get the date from date picker in my component ts file. Is this what you tried to achieve? Best, Arekitay pro commented 6 years ago
I sent Damian a sample app with DatePicker using formControl errorArkadiusz Idzikowski staff commented 6 years ago
Dear mdb2, I just checked example you sent to us and you are missing 'Pro' in your MDBBootstrapModule import. It should be MDBBootstrapModulePro.forRoot(). Best, Arekitay pro answered 6 years ago
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No
Damian Gemza staff commented 6 years ago
Dear mdb2, Could you please provide me a little bit more information about your question? It would help me to answer your question. Best Regards, Damianitay pro commented 6 years ago
This code throws a runtime error סוג מסמך