| Page 1 of 1 | [ 7 posts ] |
|
Hi I tried to modify the dates for the YUI calendar in the format DD/MM/YYYY but it still displays as MM/DD/YYYY
I used the examples frrom the localized calendars. Here is the script: http://www.sabina-ferien.de/templates/vj-08/script/cal2.js Could you tell me please what am I doing wrong ? Thanks, |
Matt ParkerYUI Contributor
|
Is the problem that they're not displaying right on the calendar, or when you select a date it displays wrong in the form input field?
If it's the first, I've no idea: it looks OK. If it's the second, your getDate function is returning the date as mm/dd/yyyy: calDate =(calDate.getMonth() + 1) + '/' + calDate.getDate() + '/' + calDate.getFullYear(); and you should be able to just swap the getMonth() bit and getDate() bit. Matt |
|
Hi Matt,
I swapped the bits as you advised and it worked. Thanks a lot, |
|
Hi,
I found an error. The calendar is attached to a text input and when I click it it displays the calendar fine. Then when I select a date it displays the date correctly in the text input. I observed if suppose I entered a wrong date and I try to select another date from the calendar without delete the text input content it displays random months or years.(ex: June 2011) Now the function to display the date is set like this: calDate = calDate.getDate() + '/' + (calDate.getMonth() + 1) + '/' + calDate.getFullYear(); // -> DD/MM/YYYY If I swap getDate with getMonth is works fine. calDate =(calDate.getMonth() + 1) + '/' + calDate.getDate() + '/' + calDate.getFullYear(); // -> MM/DD/YYYY Could somenone please give me a solution to this ? Thanks and kind regards, |
|
Not sure I follow how the string construction you mention fits in with displaying the calendar, but based on your js file...
var xy = Dom.getXY(tar), date = Dom.get(tar).value; if (date) { cal1.cfg.setProperty('selected', date); cal1.cfg.setProperty('pagedate', new Date(date), true); 1. There's no date validation going on when you pass the value to the calendar's selected or pagedate properties. The calendar will attempt to parse string dates passed in to selected and page date based on DATE_FIELD_DELIMITER, MDY_DATE_POSITION, MDY_MONTH_POSITION and MDY_YEAR_POSITION values. 2. There's also no validation going on when you pass "date" to new Date(date), which is probably not resulting in a valid Date object (e.g. new Date("foo")). The Date constructor expects epoch values, or strings defined by https://developer.mozilla.org/en/Core_J ... Date/parse. It seems like it would be a good idea to make public the _parseDate, _parseDates etc. methods which the Calendar has, so these can be used to validate string input, before passing it to Calendar, but in the interim, you'd need to do the validation yourself. Hope that helps, Satyen |
Matt ParkerYUI Contributor
|
Hi,
Is the problem now that you're trying to tell the calendar what the date is, rather than getting the date from the calendar, and it's going wrong? Calendar will expect dates as MM/DD/YYYY so you'll need to swap days and months back if you're taking the date from the text input. But I'm not sure if that is your problem. Do you have a link to see it working (or not)? Matt ... I've just had another look at your code. And yes, you'll need to put the date back into mm/dd/yyyy format in showCal. I pretty sure (but not certain) js always thinks dates are mm/dd (a pain for us Europeans!). So in showCal I think you'll need to split up the string you're getting from the text input: Code: var dateBits = date.split("/"); and then Code: cal1.cfg.setProperty('pagedate', new Date( dateBits[2], dateBits[1], dateBits[0] ), true); and you'll prob want to do a bit of checking (and maybe regex-ing) to cope with people typing in dates with other punctuation etc. I don't know Calendar well enough to know what the DateMath has in it and whether that might save you some trouble... might be worth looking. ... Third edit: you might want to listen to Satyen more than me! Matt |
|
> ... Third edit: you might want to listen to Satyen more than me!
I've come across a number of Matt's responses in working through the forum list today, and he's a perfectly good person to listen to. So don't listen to him telling you to listen to me more than listening to him. Guess it's time for lunch. |
| Page 1 of 1 | [ 7 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group