# onCalendar function

**URL:** <https://forum.servoy.com/t/oncalendar-function/344>\
**Category:** Classic Servoy\
**Created:** [September 22, 2003, 2:13pm UTC](https://forum.servoy.com/t/oncalendar-function/344 "2003-09-22T14:13:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DFehrenbach](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@DFehrenbach](https://forum.servoy.com/u/DFehrenbach)\
**Post date:** [September 22, 2003, 2:13pm UTC](https://forum.servoy.com/t/oncalendar-function/344/1 "2003-09-22T14:13:00Z")

</div>

Can anyone please suggest a reason for and a solution to my programming errors for date entry using the onCalendar function? I have very little experience with Java.  
My form has a date field that is popuated by a databasae data provider, dateentered. There is also a button next to the date field that I want to use to bring up the onCalendar pop-up function. It should load the date from the dataprovider to use as a pre-selected date value and allow the user to change it using the pop-up. I can get the pop-up to show up but the pre-selected value is not set, and when I change the date in the pop-up it does not update the dataprovider field.

the button performs this method onAction:

globals.gDate=dateentered;  
globals.getCalendarDate()  
dateentered = globals.gDate

the globals.getCalendarDate() method does this:

// Function will display a date in a Calendar prompt and return the date  
gdate=application.showCalendar();  
return(globals.gDate);

---

<div class="post-metadata">

**Author:** ![aklodner](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@aklodner](https://forum.servoy.com/u/aklodner)\
**Post date:** [September 22, 2003, 3:18pm UTC](https://forum.servoy.com/t/oncalendar-function/344/2 "2003-09-22T15:18:35Z")

</div>

Hey there,  
This is how I was able to call the Calendar Picker and set a dataprovider to what I selected:

//declare a variable ‘datepicked’ first  
var datepicked = application.showCalendar();  
//then, set the dataprovider ‘datefield’ equal to your variable  
if (datepicked != null) //checks to make sure ‘datepicked’ has something in it  
{  
forms.calendarPicker.datefield = datepicked;  
}

This works really well. The last if statement is needed in case the user hits the Cancel. Without out it, a null value would be returned to my data provider.

For the other part of your question, setting the calendar picker to a date in your data provider, I haven’t tried. Hopefully, this will at least help.

---

<div class="post-metadata">

**Author:** ![DFehrenbach](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@DFehrenbach](https://forum.servoy.com/u/DFehrenbach)\
**Post date:** [September 22, 2003, 10:30pm UTC](https://forum.servoy.com/t/oncalendar-function/344/3 "2003-09-22T22:30:18Z")

</div>

Thanks for your help. Yes that does work! Now if I could only set the date before onCalendar is called. The date is set to the system date the first time it is called, but reverts to the last selected value on subsequent calls.  
Does anyone know how this can be set before the onCalendar code is run?

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [September 23, 2003, 2:44pm UTC](https://forum.servoy.com/t/oncalendar-function/344/4 "2003-09-23T14:44:17Z")

</div>

Are you aware of the field\_type CALENDAR?(=field with button showing calendar) it seems you try to build something which is already there ![;-)]( "Wink")

---

<div class="post-metadata">

**Author:** ![aklodner](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@aklodner](https://forum.servoy.com/u/aklodner)\
**Post date:** [September 23, 2003, 3:25pm UTC](https://forum.servoy.com/t/oncalendar-function/344/5 "2003-09-23T15:25:55Z")

</div>

It’s funny, that’s how I first came up with the method. When I first started working with Servoy, I didn’t realize there was a Calendar setting for the field property!

But, now that I do have a method, I can do just about anything with it. Assign it to my own “calendar” graphic. Trigger it onFocus, or just about anything. Whether used as a property or in a method, it’s a way cool feature. Thanks!

---

<div class="post-metadata">

**Author:** ![DFehrenbach](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@DFehrenbach](https://forum.servoy.com/u/DFehrenbach)\
**Post date:** [September 24, 2003, 6:56pm UTC](https://forum.servoy.com/t/oncalendar-function/344/6 "2003-09-24T18:56:49Z")

</div>

> Are you aware of the field\_type CALENDAR?(=field with button showing calendar)

No I was not. Thanks!
