This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.
I have a calendar widget on my form whose default format is "MM / dd / yyyy" (see the attached screen capture.) When the user access the form I want the date to be problematically set to the current date. I use the following code to get the current date and format it to match the format of the calendar widget.
var curDate = new Date();
var vDateM = curDate.getMonth()+1;
var vCharsInMonth = vDateM.toString().length;
var vDateD = curDate.getDate();
var vCharsInDay = vDateD.toString().length;
var vDateY = curDate.getFullYear();
if (vCharsInMonth === 1) {
vDateM = "0" + vDateM;
}
if (vCharsInDay === 1) {
vDateD = "0" + vDateD;
}
curDate = vDateM + "/" + vDateD + "/" + vDateY;
At this point I use the following to set the data:
self.view.dteDate.setData = curDate;
This causes my app to crash.
If I use the following:
this.view.dteDate.placeholder = curDate;
This does correctly set the placeholder of the calendar widget, but when you try to save a record you get an error because the data isn't really set.
We have created one sample application to use the setdata() API for your reference. Kindly go through the attached sample application and let us know if you need any further support.
@Thewesv Dyew I have seen this page a few times. What doesn't make any sense to me are the key:value pairs required for the dictionary. I have no idea what I would enter into for the one calendar widget I have.
Thanks for your update. We took this as a feedback and try to correct our documentation. Please try to check the sample application and share us the details.
@Thewesv Dyew I was able to unzip the sample app and re-zip it and then i was able to get Visualizer to import and upgrade the app to the newest version. I am beginning my test now.
@Thewesv Dyew I have tried to test your sample app on my Windows development machine and it does not run in the Android emulator. I tested the sample app on my Mac development machine and it will run, but it definitely does not run as I would like it to. First I do not want an on-screen calendar. I just want to use the popup calendar. When it does run you get these bizarre labels that make no sense. I am becoming exceedingly disappointed in the difficulty of something so simple! Why can't you just set the data on a calendar widget?
this.view.calDOB.clearData(); //This method allows you to remove the data that is set through setData method.
this.view.calDOB.clear(); //This method allows you to enables you to clear the date in the calendar and the date format is shown. But when you use a placeholder, then placeholder text is shown instead of date format.
var today = new Date();
this.view.calDOB.validEndDate = [(today.getDate() - 1), today.getMonth() + 1, (today.getFullYear() - 18)]; //Restricting the age to be 18 and above
Similarly validStartDate property can be used to put restrictions on the selectable start date.
Find more information @ http://docs.kony.com/konyonpremises/Subsystems/Widget_User_Guide/Content/Calendar.htm
Thank you @Kingston Goldsmith ! That is the correct way to populate the calendar widget with a date. Based off of your examples, here are the two lines of code needed for setting a calendar widget to today's date:
var today = new Date();
this.view.dteDate.dateComponents = [today.getDate(), (today.getMonth() +1), today.getFullYear()];