Changes to the formslib date selector

Changes to the formslib date selector

by Tim Hunt -
Number of replies: 30
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I am going to (finally) have a go at converting the formslib date selector element to use the YUI Calendar widget. Probably like this YUI example, but with the calendar in a pop-up that only appears when one of the dropdowns is focussed. (I am not brave enough to change it to a text box with pop-up widget. I briefly started thinking about internationalisation issues, and ran screaming.)

At the same time, I am going to change the disabled pop-up to an enabled one, to avoid the whole double-negative thing. Would that cause any problems I have not thought about?
Average of ratings: -
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Tim,
Whatever you do, please could you avoid in the dropdown lists the IMHO illogical US style of date: month/day/year as shown in this screenshot from the YUI example? Can we have instead the more reasonable day/month/year usage as we have in Europe or the "computer" usage of year/month/day?
Thanks in advance,
Joseph
PS.- Sorry if my remark makes you go screaming at internationalisation issues.wink
Attachment image00.jpg
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Mike Worth -
Another vote for this, american dates are another thing that I just can't understand why anyone would see as simple. Would it not be possible to do something with the date strings in the lang files?

Mike
In reply to Mike Worth

Re: Changes to the formslib date selector

by Red Morris -

I think the date formats are already catered for to an extent with:

$string['strftimedate'] = '%%d %%B %%Y';

but I do agree that the US time format is daft. How about a 25-Jan-09 format? Then even if it's Jan-25-09 at least there's no confusion.

In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Yes, seconding what is said by Joseph, i'd suggest that the dropdown uses a string from the lang packs (an existing one in langconfig.php would b a good candidate) to get its format, or alternatively to use for this purpose a (new) setting in Admin > Location > Location settings.

Cheers, Nicolas

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
My plan is to not change the existing drop-downs at all. Just use JavaScript to pop-up the calendar when you click on one.
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@ Tim: I just updated my moodle 2.0 installation and there seems to be a bug in the open/close settings of all modules; the month dropdown list is empty (see attached screenshot). I expect this is due to the new introduction of the popup calendar not being quite finalised.

Joseph

Attachment image00.jpg
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That is very wierd. I did not change the HTML code at all (I think). That pop-up calendar is quite a good example of progressive enhancement.

So please could you do some debugging to try to work out what is going on, because it seems strange to me. Do dates appear OK elsewhere. (I know how can you check dates elsewhere if you cannot input them wink)
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Using Moodle 2.0 dev (Build: 20090407) fresh installation on XAMP local machine.
The problem is not with the popup calendar but months' names are NOT displayed anywhere in moodle when using English language. They are displayed in other languages OK. (see attached)
Weird,
Joseph
Attachment image00.jpg
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Note that Moodle uses operating system locales to generate dates. Perhaps your computer does not have the English locale installed?
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

> Note that Moodle uses operating system locales to generate dates. Perhaps your computer does not have the English locale installed?

Tim, is this something new (and quite recent) in Moodle 2.0? I thought we had completely done away with all the problems caused by having to set "locales" in Moodle installations. I still do not undertand what "system locales" are and where on earth they are located on my computer... Anyway, here I can read:

Administration Language Language settings

Sitewide localelocale Default: Empty

Choose a sitewide locale - this will override the format and language of dates for all language packs (though names of days in calendar are not affected). You need to have this locale data installed on your operating system (eg for linux en_US.UTF-8 or es_ES.UTF-8). In most cases this field should be left blank.

I always leave this field blank on my (local) Windows install and everyting works fine. And why would I have to have English locale (whatever that is, again) installed on my French computer?

Sorry to insist but the "English months not displayed" bug I reported in my previous post really looks like a very recently introduced bug in moodle 2.0. Thanks for keeping me posted...

Joseph


In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Joseph,

Just for info: I'm afraid I can't reproduce the behaviour you're describing on my Moodle 2.0dev: the month's names are displayed in english, as well as in other languages.

In reply to Nicolas Martignoni

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Nicolas,
Do you have the most recently updated moodle 2.0 on your machine? The problem I report developed quite recently, and I regularly update my moodle 2.0 on my local machine. It is really weird an un-explainable.
Joseph
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This has not changed in 2.0 (as far as I know). It has been the way it is for ages.
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
@Tim
I have finally found the culprit. The bug only occurs in Windows. File lib/moodlelib.php, around line 1340 we have this:
if ($CFG->ostype == 'WINDOWS') {
if ($localewincharset = get_string('localewincharset')) {
$textlib = textlib_get_instance();
$datestring = $textlib->convert($datestring, $localewincharset, 'utf-8');
}
}
However, in lang file lang/en_utf8/langconfig.php, we have this line:
$string['localewincharset'] = '';
It so happens that this string is the only empty string in moodle lang files...
In previous moode versions, the line
if ($localewincharset = get_string('localewincharset')) {
returned an empty string, hence the condition was not met and the current $datestring was not transformed.
But, in moodle 2.0 maybe the get_string function has changed somewhere and
if ($localewincharset = get_string('localewincharset')) {
now returns a value of [ [ localewincharset ] ] for the variable localwincharse, hence the condition is met, but of course the transformation fails, hence the bug of months not being displayed. QED.
Joseph
Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Doh! right, so it is a bug, caused by my get_string changes. I'll fix it. A lang string should be allowed to be ''.
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Tim,
As a matter of fact, I'm wondering if that test is really any use. Whichever (European) language I am using I am finding that the Windows $datestring conversion is not needed. Are you sure it could not be dropped from the code?
Joseph
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No idea, but the bug (MDL-18813) is now fixed.

I forgot to say in my last post, thank you very much for finding the cause. You probably saved me hours of debugging.
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Tim, thanks for fixing the bug.
Joseph
PS.- It did take me a few hours to track down that bug!
In reply to Joseph Rézeau

Re: Changes to the formslib date selector

by Frank Ralf -
JFTR I'm linking this to MDL-14149 (Garbled Chinese/Japanese dates on Windows machines) because the symptoms seem to be similar, perhaps the reason is related?

Frank
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Matt Gibson -
This sounds great! I can't think of any problems, but have a small feature suggestion - would it be difficult to have the other deadlines in the course and maybe other courses highlighted on the calendar? I know that for me it's quite important to make sure deadlines are evenly spaced out.
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
I try to describe the problem I meet when I copy a question to the web.
In our daily talk if I ask you "When were you born?" I expect you reply me with three information: a day, a month and an year.
If I ask you "When did you start to use Moodle?" I don't expect a day but only an answer with a month and an year or, at least, with the year only.
It shuld be fine if the developer could format the date field in mform in order to request a complete date or a "partial" date with only month and year.
In reply to Daniele Cordella

Re: Changes to the formslib date selector

by Mike Worth -
I agree this would be useful, the way I see it this would be a new input type (dateApproxSelector maybe?). It wouldn't need a calendar, just a couple of selects (or maybe even text inputs to type it in)

Mike
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Hi Tim -

Can you point me to where in the code you did this? I was looking in 'lib/form/dateselector.php', but I can't see anything in there that does this.

mike
In reply to Mike Churchward

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Doh! we don't seem to have had the tracker issue mentioned in this thread yet. It is MDL-16592. You can get the changes from there.
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Thanks
In reply to Mike Churchward

Re: Changes to the formslib date selector

by Alejandro Michavila Pallarés -
Hello,

I don't know if this is the right place to ask, but is there a method I can use to have a date selector on the settings.php file of my module?.

I know I can use admin_setting_configselect(), but I haven't seen something like admin_setting_configdate_selector().

Thanks.
In reply to Alejandro Michavila Pallarés

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That sounds like a good idea, it certainly ought to exist, but I don't think anyone has created it yet.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Changes to the formslib date selector

by Alejandro Michavila Pallarés -
Yeah, it would be great.
In reply to Alejandro Michavila Pallarés

Re: Changes to the formslib date selector

by Alejandro Michavila Pallarés -
Well, may be we can vote for this new feature: MDL-24413.
In reply to Alejandro Michavila Pallarés

Re: Changes to the formslib date selector

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you wanted to be more productive that voting, you could try writing the code.

Making a new subclass of admin_setting is pretty easy. In this case, the trick would be to output exactly the same HTML as a date selector in a formslib form. Then you could use exactly the same JavaScript code to make it flashy.