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

Louis-Guillaume said…
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).
Anonymous 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!
Anonymous 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?
Anonymous 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.
Anonymous 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
Anonymous 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

Filtering in the APEX Interactive Grid

Remember Oracle Forms? One of the nice features of Forms was the use of GLOBAL items. More or less comparable to Application Items in APEX. These GLOBALS where often used to pre-query data. For example you queried Employee 200 in Form A, then opened Form B and on opening that Form the Employee field is filled with that (GLOBAL) value of 200 and the query was executed. So without additional keys strokes or entering data, when switching to another Form a user would immediately see the data in the same context. And they loved that. In APEX you can create a similar experience using Application Items (or an Item on the Global Page) for Classic Reports (by setting a Default Value to a Search Item) and Interactive Reports (using the  APEX_IR.ADD_FILTER  procedure). But what about the Interactive Grid? There is no APEX_IG package ... so the first thing we have to figure out is how can we set a filter programmatically? Start with creating an Interactive Grid based upon the good old Employ

Stop using validations for checking constraints !

 If you run your APEX application - like a Form based on the EMP table - and test if you can change the value of Department to something else then the standard values of 10, 20, 30 or 40, you'll get a nice error message like this: But it isn't really nice, is it? So what do a lot of developers do? They create a validation (just) in order to show a nicer, better worded, error message like "This is not a valid department".  And what you then just did is writing code twice : Once in the database as a (foreign key) check constraint and once as a sql statement in your validation. And we all know : writing code twice is usually not a good idea - and executing the same query twice is not enhancing your performance! So how can we transform that ugly error message into something nice? By combining two APEX features: the Error Handling Function and the Text Messages! Start with copying the example of an Error Handling Function from the APEX documentation. Create this function