Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar initial value not visible with reactive forms #1226

Closed
iguissouma opened this issue Nov 7, 2016 · 14 comments
Closed

Calendar initial value not visible with reactive forms #1226

iguissouma opened this issue Nov 7, 2016 · 14 comments
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@iguissouma
Copy link

I having an issue displaying the initial value in a calendar.
My code is like below:

<p-calendar id="startDate" [inline]="false" dateFormat="yy-mm-dd" formControlName="startDate" [(ngModel)]="program.startDate"></p-calendar>

program.startDate is a date not null (startDate: Wed Nov 09 2016 01:00:00 GMT+0100 (Paris, Madrid))

I have blank value on the calendar like below:

2016-11-07_19h05_52

When I select another date the date is shown:
2016-11-07_19h09_38

I'm using the following version "primeng": "^1.0.0-rc.1" with ultima-ng theme.

Thanks.

@kcsahoo
Copy link

kcsahoo commented Nov 7, 2016

Please use rc.3 for correct operation

@tdi83
Copy link

tdi83 commented Nov 8, 2016

I have the same issue with rc.3.

loanDate is new Date('2013-06-30')
Value is displayed in DatePicker, but missing in the text field of calendar.

@iguissouma
Copy link
Author

I updated to the rc3 today, I can confirm I have the same issue.
I deleted prime-ng from node_modules the run npm install

npm install
frontend@0.0.0 C:\dev\clients\cf\projects\op\frontend
└── primeng@1.0.0-rc.3

Run again my application.
The text field of calendar is still empty.

@dshupe
Copy link

dshupe commented Nov 8, 2016

We are also having issues with the initial date showing blank in the input field. In our case it happens when we have a form group that contains another form group of controls. We want to render the calendar control in a table like this:

<table class="table table-hover table-bordered table-responsive table-sm">
    <tr *ngFor="let subGroup of someForm.controls;">
        <td>
            <p-calendar [formControl]="subGroup.controls.DateExecuted"></p-calendar>
        </td>
    </tr>
</table>

The initial date value is not displaying. We cannot use formControlName in this case since we are inside an *ngFor of the subGroup of controls.

@iguissouma
Copy link
Author

Same behaviour in rc4

@Mrtcndkn Mrtcndkn changed the title p-calendar intial value not visible p-calendar initial value not visible with reactive forms Nov 10, 2016
@Mrtcndkn Mrtcndkn added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Nov 10, 2016
@Mrtcndkn Mrtcndkn added this to the 1.0.0 milestone Nov 10, 2016
@Mrtcndkn Mrtcndkn self-assigned this Nov 10, 2016
@cagataycivici cagataycivici changed the title p-calendar initial value not visible with reactive forms Calendar initial value not visible with reactive forms Nov 10, 2016
@cagataycivici cagataycivici changed the title Calendar initial value not visible with reactive forms Calendar initial value not visible Nov 10, 2016
@cagataycivici cagataycivici changed the title Calendar initial value not visible Calendar initial value not visible with reactive forms Nov 10, 2016
@dshupe
Copy link

dshupe commented Nov 14, 2016

Verified that this is not fixed in rc4. Still cannot see initial value in the textbox of the p-calendar, but when the calendar drops down. the correct date is selected.

@ShankarSumanth
Copy link

Hi Guys,
I have put together a working sample for this issue. I believe that the initial value is usually initialized in the constructor or the onInit method and my guess is that untill the UI is rendered these initial value is not picked up by angular. My idea was to insert this value in the ngAfterViewInit method so that once the view is initialized by angular and angular starts tracking these values it is easy to update the value.
Strange but works.

html file
`<form [formGroup]="registerForm">

<label>Start Date</label>

<p-calendar [(ngModel)]="value" formControlName="calendar" ></p-calendar>
`

ts file
`export class TestComponent implements AfterViewInit {

value: Date;

registerForm: FormGroup;

constructor(private formBuilder: FormBuilder) {

    this.value = new Date();

    this.registerForm = this.formBuilder.group({
        calendar: ''
    });
    this.registerForm.get('calendar').valueChanges.subscribe(value =>
        console.log(value)
    );
}

ngAfterViewInit() {
    this.registerForm.get('calendar').setValue(this.value);
}

}`

Hope this solution helps you all.

@iguissouma
Copy link
Author

This issue is fixed in rc5.

@atigm
Copy link

atigm commented Sep 25, 2017

I have the same problem with "primeng": "4.2.1" !

<form ....
<p-calendar [(ngModel)]="model.date" name="date"
                        [showIcon]="true" showTime="showTime" hourFormat="24" >
</p-calendar>

Thanks.

@markgoho-EDT
Copy link

Still seeing this in v5

@milindwmahajan
Copy link

milindwmahajan commented Mar 8, 2018

Try converting date to ISO before using it on the form.
using moment
moment(r.birthDate).toDate();

@AmirGilboa
Copy link

Yes! that that did the trick. 2 hours i'm on this. thanks @milindwmahajan .
converting to ISO solved it.

@lucho120
Copy link

Tenía el mismo problema, solo tuve que hacer esto:
var dateValue='2023-02-11';
var dateFormat= new Date(dateValue)

con eso ya aparece la fecha en mi p-calendar
<p-calendar [showIcon]="true" formControlName="dateFormat">

@enanglaw
Copy link

wrap the date format in a square bracket e.g. dateFormat="yy-mm-dd" will be [dateFormat]="yy-mm-dd"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests