ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

Picking a date does not set the value in ngForm #177

Closed mihailo-misic closed 7 years ago

mihailo-misic commented 7 years ago

Inside a template driven from (ngForm) when I choose a date using the datetime-picker the value is not set in the form object. But once i manually change something or input the date myself the form object once submitted is correct.

Plunker Example

I don't think this should be the expected behaviour. Am I doing something wrong? This seems quite simple and intuitive.

Thank you for your time.

allenhwkim commented 7 years ago

Please use example given from README.md

   <form [formGroup]="myForm">
     <input 
       required
       [(ngModel)]='myVar' 
       formControlName="date" 
       ngui-datetime-picker
        date-only="true"/>
   </form>
   myForm.controls.date: {{myForm.controls.date.value}}

https://plnkr.co/edit/su2aiL?p=preview

You are missing formControlName

mihailo-misic commented 7 years ago

@allenhwkim this is what i did in the end. You do not have to have formGroup and formControlName for this template driven form to work. My example is a completely working form, there is nothing missing and everything was working, except the plugin.