Skip to main content

How to replace the default APEX calendar with jQuery calendar...


One of the things I talked about during my presentations at OOW and UKOUG is how to replace the (not so good looking) default APEX calendar with a (much nicer) jQuery version. So here are the steps:
1. Download jQuery and jQuery UI from the jQuery website. Upload the jQuery javascript files to your webserver (or into your database if you are using the EPG). Or use GoogleCode...
2. Create a HTML Region on Page 0, containing the references to the uploaded stylesheets and javascript files. Something like this:

3. Set the "Display as" property of the date fields to 'Text Field" and set the "HTML Form Element Attributes" to : class="datefield".
4. Back in Page 0, add a function to the jQuery 'document ready' function to add the jQuery datepicker to all fields with that class:
5. Run your page and see the results. It should something like the picture on top. I created - a very small - 'running' demo on apex.oracle.com.

Update: In FF all works great, but in IE6 and IE7 the vertical position of the calendar DIV seems to be calculated wrong (using jQuery 1.2.6). Probably a bug in the jQuery lib...

Comments

Roel,

Have you tried it using IE 6? The calendar is not showing right.
I did a similar demo but I didn't release it since I can't get it to run perfectly for IE.
http://apex.oracle.com/pls/otn/f?p=987654321:15:0

To make it work perfectly, I used Dimitri jQuery library used by Apex Blog Aggregator.
http://apexblogs.info/pls/apex/f?p=113:8:0

I didn't have much time to find what's the difference between both version of jQuery.

If you find a fix, please let me now.

Thanks,
Anonymous said…
Pardon my ignorance (and thanks for educating us). That seems like a lot of CSS and JS to include in page 0. I realized that if they're on the web server they'll get cached, but do you need to include them all?

Looks like fun stuff and actually more useful than my "goody for eye-candy" comment would suggest.

Thanks for sharing, again.
Roel said…
@Louis-Guillaume : You're right. It is probably a bug in JQuery 1.2.6.

@Stew : The files also get cached on the client, so only when a new version is available it gets downloaded. And I reduced the number of includes to the minimum (see the post).
Jon Barwell said…
As an APEX developer but a non-Javascript developer, could you explain what you mean by "..Jquery document ready function...". I don't understand which section this would go in in page zero.

Thanks,

Jon
Anonymous said…
As someone who knows virtually nothing about Javascript, can you explain the last step...add a function to the jQuery 'document ready' function...? Thanks!
Jon Barwell said…
Roel,

I have now managed to get this working and looks really good. The only problem I am having is that field 'Read Only' conditions in APEX are not applied. Is this something that you have come across?

Thanks,

Jon
Roel said…
@Jon : I don't get what you mean by "field 'Read Only' conditions are not applied". If you have a read-only date field, you can choose not to add the class to that field and it won't add a calendar. If the field is marked read-only at runtime...you have to disable the datepicker also:
$(fieldname).datepicker("disable")

Is that what you mean?
Jon Barwel said…
Roel,
For the field in APEX I have a PL/SQL expression on my date field that defines whether the field is read only or not within APEX.

TO_DATE(:P_EFTV_FROM,'DD/MM/YYYY') > TO_DATE(SYSDATE,'DD/MM/YYYY')

i.e. disable if prior to today.

However, the state of the field is not changed using the standard APEX functionality where the javascript class has been applied. In APEX the field would normally be 'greyed' out.

I thought that the logic, $(fieldname).datepicker, ("disable"), simply disabled the button but how do you disable the data entry?

Hope this is clear.

Jon
Roel said…
@Jon: If you use $("input.datefield").datepicker instead of
$(".datefield").datepicker it seems to work properly.
Example on the apex.oracle.com page in the post.
Jon Barwell said…
Roel,

I think my problem was having more than one date field on the screen. However, using $("input.datefield").datepicker works perfectly.

Thanks for the help.

Regards,

Jon
Alex said…
Roel,

Even though Jon got it to work, to me (just getting started with APEX and really dumb with Javascript) it is still not clear what you mean with "4. Back in Page 0, add a function to the jQuery 'document ready' function to add the jQuery datepicker to all fields with that class: "

Could you elaborate at little bit more, please?
Roel said…
@Alex:
The $(function(){"code goes here"}); is (what I referred as) the 'document.ready' function. All the "code goes here" will be executed after the DOM is loaded. So in the example that code is:
$("input.datefield").datepicker(). So the datepicker() function is executed for every INPUT field with class="datefield".
Just cut'n'paste that code and (hopefully) you'll see that working.
Good luck and thanks for commenting,
Roel
Anonymous said…
I was able to install jquery and tried to use this data picker in APEX 3.1.1, but it looks like I can't set minDate lesser than 1999! That means I can't use it to enter birthdays :(
Roel said…
@burbilog ; You can add a yearRange parameter, like yearRange : "-50:+1" to show all years between 50 years back and next year.
Ligon said…
Hi Roel,

Thanks a lot for the information. I was trying to make it happen, but the background of the calendar comes blank. I have no idea what causing it, great if you could have a look and provide some helpful hint.

http://apex.oracle.com/pls/otn/f?p=JQueryDatePicker2

Temporary Dev user account
Workspace: ligon_apex
username/pass: test

Application Alias : JQueryDatePicker2

ID: 42029

Thank you and Regards
Ligon
Roel said…
@Ligon
I uploaded another ui.datepicker.css and flora.datepicker.css. I see some color now. Seems like your missing some color setting in your css.
Ligon said…
Hi Roel,

Thanks a ton for looking into it and spending time to get it working. I could see the colors now, Although there looks to be some alignment issues, which off course something I could play around and figure out.

Appreciate your quick response.

Thank you and Regards
Ligon
tokke said…
hi roel,

is there a way in the datetimepicker to only have selectable options eg. 15, 30, 45 and 0 for the minutes rather than the whole sequence of 0 upto and including 59?

i have programmed something similar in PHP. now jquery & apex, please?

thanks a lot.

kind regards,


-victorbax-

Popular posts from this blog

apex_application.g_f0x array processing in Oracle 12

If you created your own "updatable reports" or your custom version of tabular forms in Oracle Application Express, you'll end up with a query that looks similar to this one:
then you disable the "Escape special characters" property and the result is an updatable multirecord form.
That was easy, right? But now we need to process the changes in the Ename column when the form is submitted, but only if the checkbox is checked. All the columns are submitted as separated arrays, named apex_application.g_f0x - where the "x" is the value of the "p_idx" parameter you specified in the apex_item calls. So we have apex_application.g_f01, g_f02 and g_f03. But then you discover APEX has the oddity that the "checkbox" array only contains values for the checked rows. Thus if you just check "Jones", the length of g_f02 is 1 and it contains only the empno of Jones - while the other two arrays will contain all (14) rows. So for processing y…

Refresh selected row(s) in an Interactive Grid

In my previous post I blogged about pushing changed rows from the dabatase into an Interactive Grid. The use case I'll cover right here is probably more common - and therefore more useful!

Until we had the IG, we showed the data in a report (Interactive or Classic). Changes to the data where made by popping up a form page, making changes, saving and refreshing the report upon closing the dialog. Or by clicking an icon / button / link in your report that makes some changes to the data (like changing a status) and ... refresh the report.  That all works fine, but the downsides are: The whole dataset is returned from the server to the client - again and again. And if your pagination size is large, that does lead to more and more network traffic, more interpretation by the browser and more waiting time for the end user.The "current record" might be out of focus after the refresh, especially by larger pagination sizes, as the first rows will be shown. Or (even worse) while you…

Dockerize your APEX development environment

Nowadays Docker is everywhere. It is one of the main components of Continuous Integration / Continuous Development environments. That alone indicates Docker has to be seen more as a Software Delivery Platform than as a replacement of a virtual machine.

However ...

If you are running an Oracle database using Docker on your local machine to develop some APEX application, you will probably not move that container is a whole to test and production environments. Because in that case you would not only deliver a new APEX application to the production environment - which is a good thing - but also overwrite the data in production with the data from your development environment. And that won't make your users very excited.
So in this set up you will be using Docker as a replacement of a Virtual Machine and not as a Delivery Platform.
And that's exactly the way Martin is using it as he described in this recent blog post. It is an ideal way to get up and running with an Oracle database …