Wednesday, August 8, 2012

Oracle Apex:How to disable date field (DATE_POPUP) in SQL report?

Consider below mentioned scenario :  

 We are displaying employee information. If employee city is New York then not allow user to edit START DATE field.

To complete this task we are going to follow below mentioned steps.

1) Create classic SQL report.  Put below mentioned query in region source.

--------------------------------------------------------------------------------------
SELECT

FIRST_NAME,
LAST_NAME,
--below we are checking if city is new york disable date item.
DECODE(
               upper(trim(CITY)), upper(trim('New York')),   (APEX_ITEM.DATE_POPUP(20,2,START_DATE,'mm/dd/yyyy',10,11,'DISABLED')), (APEX_ITEM.DATE_POPUP(10,1,START_DATE,'mm/dd/yyyy',10,11))
      ) AS "Start Date",


END_DATE,
CITY,
DESCRIPTION

FROM EMPLOYEE
--------------------------------------------------------------------------------------

2)  APEX_ITEM.DATE_POPUP function dynamically generates a date field that has a popup calendar button.

APEX_ITEM.DATE_POPUP(
    p_idx          IN    NUMBER, 
    p_row          IN    NUMBER,
    p_value        IN    VARCHAR2 DEFAULT,
    p_date_format  IN    DATE DEFAULT,
    p_size         IN    NUMBER DEFAULT,
    p_maxlength    IN    NUMBER DEFAULT,
    p_attributes   IN    VARCHAR2 DEFAULT)
    RETURN VARCHAR2;


Explanation:

APEX_ITEM.DATE_POPUP(
                    20, -- ' Number that determines which APEX_APPLICATION global variable will be used.Valid range of values is 1 to 50.'
                    2, --  This parameter is deprecated. Anything specified for this value will be ignored
                    START_DATE, --  Value of a field item (column name)
                    'mm/dd/yyyy', -- Valid database date format
                    10, --  Controls HTML tag attributes
                    11, -- Determines the maximum number of enterable characters. Becomes the maxlength attribute of the  input HTML tag
                    'DISABLED'  -- Extra HTML parameters you want to add (like disabled)
                    )


 Reference Please visit this link for more information
 http://docs.oracle.com/cd/B28359_01/appdev.111/b32258/api.htm#CHDFDDEI

3)  Result : Start Date Field is disabled for New York City.