I am trying to call apex.widget.datepicker to apply a custom datepicker with the time to a field inside “Execute when Page Loads”. In previous versions of Apex this worked fine but we have recently migrated to Apex 4.1.1.00.23
The JS error I get when the page loads is “TypeError: can’t convert undefined to object”
On another note I could change the type of field to date, but how can I then customise the jquery date object that has been binded to that particular field?
When i got access to a 4.1.1 workspace (since apex.oracle.com was updated to 4.2) I promptly tried to reproduce the issues. However, i can’t!
I’d swear i had an issue on apex.oracle.com, but i’m not so sure anymore whether i made a mistake.
Actually, 4.1.0 and 4.1.1 respond exactly the same, as i would actually expect them to. 4.2 is different, but only by a little. I don’t know why i have wasted so much time up until now, i must have really been missing some obvious logical flaw.
I don’t know what changed between 4.0 and 4.1 though, so i’m not sure what you did to initialize a datepicker in 4.0. If all you had to do was to call
apex.widget.datepickeron an item to get it to work, in 4.1 that changes a little as there is an extra step involved.Before calling
apex.widget.datepicker, you have to make sure a locale has been loaded. I spied this from inspecting the ajax calls made by apex when opening the actions > filter menu. That code appends a script tag with a source set to datepicker locale files in theapex_imagesdirectory. The file initializes some variables in the datepicker.For example, an application with language english =
'en', would initialize asapex.jQuery.datepicker.regional['en']This is important, because if this doesn’t happen, you get the
undefinedobject error, since the widget code attempts to access those locale variables. If the script code has not been appended, they won’t be, andapex.widget.datepickerwill throw an error.To make sure the datepicker code works, you will need to include the locale javascript file. You can do this by adding it to your page header, in the page itself, the template, or you can do it dynamically: it’s up to you to decide the best place.
Here is an example of dynamically adding the locale file:
This will get the file in the given directory (same as actions>filter would do), and it looks as this:
Now, do notice that that path has some hard-coding issues. There is ‘/i/’, the jquery version, and the locale. Not much can be done about the jquery version.
/i/can be replaced byapex_img_dirlocale can be caught with the
BROWSER_LANGUAGEapplication variableshould do the trick (inspect your ajax call to make sure!)
Once the script has been included, it should be safe to call apex.widget.datepicker!
Now, i’ve also been experimenting on 4.2, and it’s mostly the same there. The only thing which has changed is that you have to include the widget code!
That should cover most of it.