21.18 SWITCH Function
This function dynamically generates flip toggle item. If On/Off value and label are not passed, it renders Yes/No toggle. Similar to other functions available in the APEX_ITEM package, switch function is designed to generate forms with F01 to F50 form array elements.
                  
Syntax
APEX_ITEM.SWITCH(
     p_idx IN NUMBER,
     p_value IN VARCHAR2,
     p_on_value IN VARCHAR2 DEFAULT 'Y',
     p_on_label IN VARCHAR2 DEFAULT 'Yes',
     p_off_value IN VARCHAR2 DEFAULT 'N',
     p_off_label IN VARCHAR2 DEFAULT 'No',
     p_item_id IN VARCHAR2 DEFAULT NULL,
     p_item_label IN VARCHAR2,
     p_attributes IN VARCHAR2 DEFAULT NULL)
     RETURN VARCHAR2;
Parameters
Table 21-18 SWITCH Parameters
| Parameter | Description | 
|---|---|
| 
 | Form element name. For example, 1 equals F01 and 2 equals F02. Typically the  | 
| 
 | Form element current value. | 
| 
 | The value of the item if the user picks On option. | 
| 
 | The display text for the On option. | 
| 
 | The value of the item if the user picks Off option. | 
| 
 | The display text for the Off option. | 
| 
 | HTML attribute ID for the <input> tag. Try concatenating some string with rownum to make it unique. | 
| 
 | Invisible label created for the item. | 
| 
 | Additional HTML attributes to use for the form item. | 
Example
The following example demonstrates the use of APEX_ITEM.SWITCH to generate a Yes/No flip toggle item where:
                  
- 
                        A form array element F01 will be generated ( p_idxparameter).
- 
                        The initial value for each element will be equal to N (p_valueparameter).
- 
                        A HTML ID attribute will be generated for each row with the current rownum to uniquely identify. ( p_item_idparameter). An ID of'IS_MANAGER_2'is generated for row 2.)
- 
                        A HTML label element will be generated for each row ( p_item_labelparameter).
SELECT
  ename "Name",
  APEX_ITEM.SWITCH ( 
       p_idx => 1,
       p_value => 'N',
   p_item_id => 'IS_MANAGER_'||rownum,
       p_item_label => apex_escape.html(ename)||': Is Manager' )
"Is Manager"
FROM emp;Parent topic: APEX_ITEM