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!

2 thoughts on “Oracle APEX Datepicker Dynamic Min/Max Change

    • In 22.2 and higher, this code is no longer necessary. Use the elements in the Datepicker Settings:

      The trick is, the Item or Static value need to be in a specific format. Read the Help on the Datepicker Settings elements for more details:
      “The date value can be an absolute value in ‘YYYY-MM-DDTHH24:MI:SS’ or ‘YYYYMMDDHH24MI’ format or a relative value with respect to today’s date, such as +7d, or a dynamic value using substitution syntax, providing the substitution returns the correct date format or relative value.

      Relative date values include:

      y
      + / – years from today’s date
      m
      + / – months from today’s date
      w
      + / – weeks from today’s date
      d
      + / – days from today’s date
      Examples
      2009-06-25T23:11:00
      200906252311
      +1y+1m+1w
      -1m-1w
      +1m-1d
      &P1_MAX_SIGNUP_DATE.

      The Datepicker now works the way it is supposed to – imagine that! And Thank You APEX Team.

Leave a Reply