Oracle APEX Datepicker Dynamic Min/Max Change

I had a recent requirement to dynamically change the Minimum date on the datepicker, without a full page refresh (which I could have done … but, ick). Turns out its pretty easy.

The key to dynamically change an APEX datepicker item settings is this piece of JavaScript:

$('#P1_DATEPICK').datepicker("option","minDate",$("#P1_DATEPICKER_MIN_VAL").val());

where P1_DATEPICK is your datepicker item, and P1_DATEPICKER_MIN_VAL is an item – hidden or not – that holds your minimum date for the datepicker.

Use those Minimum Date and Maximum Date settings (this is what they are for):

Oracle APEX Datepicker Settings
Use the Datepicker item Settings

Assuming your hidden item name is P1_DATEPICKER_MIN_VAL, Set the Minimum Date to &P1_DATEPICKER_MIN_VAL. Similar for Maximum Date. Note the & … . syntax.

Create a dynamic action on whatever event it is that triggers a change in your datepicker minimum value. In that dynamic action, create whatever True actions are necessary to set the datepicker minimum value item value – Set Value, Execute PL/SQL Code, whatever works for your needs.

Next, in the same dynamic action, add a True action of type Execute JavaScript Code:

$('#P1_DATEPICK').datepicker("option","minDate",$("#P1_DATEPICKER_MIN_VAL").val());

That’s the piece that does the dynamic datepicker setting change.

In this post I purposely left out the details of creating and setting items. Those details are all specific to your specific requirements. If anyone wants assistance for your particular case simply contact me, I am glad to help.

Happy Coding!

Leave a Reply