- Since:
- 5.0
This is the Element context that actions are scoped within as given in the apex.actions.createContext call.
Type:
- Element
This is type name of the actions context as given in the apex.actions.createContext call. The typeName of the global context apex.actions is "global".
Type:
- string
Add an actions.action object or an array of actions.action objects to this actions context. The action name must be unique within the context and the shortcut if any must be unique within the context and valid. Debug warnings are logged if any of these conditions are not met. See also actions#remove.
Note: The global actions context (apex.actions) does not exist until after the DOM is ready.
Actions should be added after the DOM is ready. For code in JavaScript files or in APEX page attribute
"Function and Global Variable Declaration" you can wrap the call to add
in the jQuery ready handler if needed. For example:
$( function() {
apex.actions.add(...);
} );
Parameters:
Name | Type | Description |
---|---|---|
pActions |
actions.action | Array.<actions.action> | The action or an array of actions to add. |
Returns:
- Type
- boolean
Examples
This example adds one action to the global actions context.
apex.actions.add({
name: "send-email",
label: "Send Email",
action: function(event, focusElement) {...}
});
This example adds an array of actions to the context
log1
returned by apex.actions.createContext.
log1.add([{
name: "clear-log",
label: "Clear",
action: function(event, focusElement) {...}
},
{
name: "verbose",
label: "Verbose",
get: function() {...},
set: function(value) {...}
},
...
]);
Add one or more actions.action objects from simple list markup. This is useful in cases where it is easier to render list markup than an array of action objects. This does not support adding actions with functions but action functions can be added either before or after.
The markup expected by this method overlaps with what the menu widget expects.
Expected markup:
An element with a <ul>
child. The
<ul>
has one or more <li>
elements each one representing an action.
The <li>
element can contain either an
<a>
or <span>
element.
Action property | Comes from |
---|---|
name | li[data-id] |
label | a or span content |
title | a[title] or span[title] |
href | a[href] |
target | a[target] |
disabled | true if li[data-disabled=true] false otherwise |
hide | true if li[data-hide=true] false otherwise |
shortcut | li[data-shortcut] |
icon | li[data-icon] If the value has a space the icon is the word after the space otherwise it is the whole value |
iconType | li[data-icon] If the value has a space the type is the word before the space |
If there is no name or label or the value of <href>
equals
"separator" then no action is created for that <li>
.
If the <li>
has a <ul>
child the <ul>
is processed recursively.
Parameters:
Name | Type | Description |
---|---|---|
pList$ |
jQuery | The jQuery object representing the parent of the actions list markup. |
Examples
This example shows markup for two actions.
<div id="myActionList">
<ul>
<li data-id="goto-page-1">
<a href="...">Page One</a>
</li>
<li data-id="goto-page-2">
<a href="...">Page Two</a>
</li>
</ul>
</div>
This example shows how to turn the above markup into actions in the global context.
apex.actions.addFromMarkup($("#myActionList"));
Add a keyboard shortcut synonym for an action. Debug warnings are logged if there are problems. See also actions#removeShortcut.
This allows an action to have more than one shortcut key to invoke it.
The shortcut
property of the action is not affected.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pShortcutName |
actions.shortcutName | The keyboard shortcut synonym to add. | |
pActionName |
string | The name of the action to add a shortcut for. | |
pChoiceValue |
string |
<optional> |
Choice value only if the action is a radio group. The shortcut will select the given choice. |
Returns:
- Type
- boolean
Example
This example adds a shortcut synonym for action "send-email".
apex.actions.addShortcut("Ctrl+Shift+E", "send-email");
Return the keyboard shortcut name formatted for the aria-keyshortcuts attribute.
Parameters:
Name | Type | Description |
---|---|---|
pShortcutName |
actions.shortcutName | Keyboard shortcut to get the ARIA label for. |
Returns:
- Type
- string | null
Remove all actions from this actions context.
Example
This example removes all the actions from the global context.
apex.actions.clear();
Disable UI elements associated with the action by setting disabled
property to true.
This is a convenience method to disable without having to call actions#lookup and
actions#update.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action to disable. | |
pArgs |
object |
<optional> |
An object containing arguments for the action. If the action is bound
to many row or item instances in a report the pArgs property
with the same name as the actions.action idArg property
value is used to determine which UI element to disable. |
Example
This example disables the "send-email" action.
apex.actions.disable( "send-email" );
This is used to disable all shortcuts temporarily. Call at the start of a user interaction that should have shortcuts disabled for example a custom popup. Call actions#enableShortcuts when finished. It is called automatically when APEX modal dialogs or menus open. Calls can be nested. For each call to disableShortcuts there should be a corresponding call to actions#enableShortcuts.
Enable UI elements associated with the action by setting disabled
property to false.
This is a convenience method to enable without having to call actions#lookup and
actions#update.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action to enable. | |
pArgs |
object |
<optional> |
An object containing arguments for the action. If the action is bound
to many row or item instances in a report the pArgs property
with the same name as the actions.action idArg property
value is used to determine which UI element to enable. |
Example
This example enables the "send-email" action.
apex.actions.enable( "send-email" );
This is used to enable all shortcuts after they were disabled with actions#disableShortcuts. It is called automatically when APEX modal dialogs or menus close. Calls can be nested. For each call to actions#disableShortcuts there should be a corresponding call to enableShortcuts.
Return the current value of a radio group or toggle action.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action. | |
pArgs |
object |
<optional> |
An object containing arguments for the get function. The object properties are the argument names and the property values are the argument values. This is passed to the action's get function. |
Returns:
- Type
- string
Example
This example returns the current choice of radio group action "change-view" of the interactive grid region with static id "emp". The Interactive Grid method getActions returns the actions context for the region.
apex.region( "emp" ).call( "getActions" ).get( "change-view" );
Hide UI elements associated with the action by setting the hide
property to true.
This is a convenience method to hide without having to call actions#lookup and
actions#update.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action to hide. | |
pArgs |
object |
<optional> |
An object containing arguments for the action. If the action is bound
to many row or item instances in a report the pArgs property
with the same name as the actions.action idArg property
value is used to determine which UI element to hide. |
Example
This example hides the "send-email" action.
apex.actions.hide( "send-email" );
Invoke the named action. Even though pEvent and pFocusElement are optional it is recommended to always include them.
This has no effect if the action is hidden or disabled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | Name of the action to invoke. | |
pEvent |
Event |
<optional> |
Browser event that caused the action to be invoked. |
pFocusElement |
Element |
<optional> |
The element that will receive focus when the action is complete unless the action returns true. This is likely also the element that had focus when the action was invoked. |
pArgs |
object |
<optional> |
An object containing arguments for the action. The object properties are the argument names and the property values are the argument values. This is passed to the action function as the third argument. This is not used if the action has only an href. |
Returns:
- Type
- boolean | undefined
Example
This example invokes the "send-email" action when something is clicked.
$( "#something" ).click( function( event ) {
apex.actions.invoke( "send-email", event, event.target );
} );
Return an array of actionName, label pairs for all actions in the context. For actions with choices there is an array item for each choice.
Returns:
- Type
- Array
Example
This example writes to the console a list of all the actions in the global context.
apex.actions.list().forEach(function(a) {
console.log( "Action Label: " + a.label +
", Name: " + a.name +
(a.choice !== undefined ? ", Choice: " + a.choice : "" ) );
});
listShortcuts(pWithMarkup) → {Array.<actions.shortcutListItem>}
Return a list of all shortcuts in the context.
Parameters:
Name | Type | Description |
---|---|---|
pWithMarkup |
boolean | Optional default is false. If true wrap the display name in HTML markup. |
Returns:
- Type
- Array.<actions.shortcutListItem>
Example
This example writes to the console all the shortcuts in the global context.
var i,
shortcuts = apex.actions.listShortcuts();
for ( i = 0; i < shortcuts.length; i++ ) { // for each shortcut
console.log("Press shortcut " + shortcuts[i].shortcutDisplay + " to " + shortcuts[i].actionLabel );
}
lookup(pActionName) → {actions.action}
Lookup and return an action by name. If you modify the properties of the action you may need to call actions#update to update any associated UI elements or shortcuts. If you modify the choices of the action then call actions#updateChoices.
Parameters:
Name | Type | Description |
---|---|---|
pActionName |
string | The name of the action to return. |
Returns:
- Type
- actions.action
Example
This example updates the label and title of an action.
var action = apex.actions.lookup( "my-action" );
action.title = "New Title";
action.label = "New Label";
apex.actions.update( "my-action" );
Register a callback function to be notified when an action changes. This is used to update UI elements associated with an action when that action state changes. The most common elements including buttons, checkbox and radio group inputs, select lists, and menus are already handled.
Parameters:
Name | Type | Description |
---|---|---|
pCallback |
function | function notifyObservers( action, operation, args )
|
Remove one or more actions.action objects from this actions context. See also actions#add.
Parameters:
Name | Type | Description |
---|---|---|
pActions |
actions.action | string | Array.<actions.action> | Array.<string> | The action or action name or an array of actions or an array of action names to remove. |
Examples
This example removes one action from the global action context.
apex.actions.remove( "send-email" );
This example removes an array of actions from the context
log1
returned by apex.actions.createContext.
log1.remove( ["clear-log", "verbose"] );
Remove a keyboard shortcut synonym for an action. See also actions#addShortcut
Parameters:
Name | Type | Description |
---|---|---|
pShortcutName |
actions.shortcutName | The keyboard shortcut synonym to remove. |
Returns:
- Type
- boolean
Example
This example removes a shortcut synonym.
apex.actions.addShortcut( "Ctrl+Shift+E" );
Set the value of a radio group action or toggle action.
This has no effect if the action is hidden or disabled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action. | |
pValue |
string | boolean | The value to set. | |
pArgs |
object |
<optional> |
An object containing arguments for the set function. The object properties are the argument names and the property values are the argument values. This is passed as the last argument to the action's set function. |
Example
This example sets the current choice of radio group action "change-view" of the interactive grid region with static id "emp" to "detail". The Interactive Grid method getActions returns the actions context for the region.
apex.region( "emp" ).call( "getActions" ).set( "change-view", "detail" );
Return the friendly display string for a keyboard shortcut name.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pShortcutName |
actions.shortcutName | Keyboard shortcut to get the display string for. | |
pWithMarkup |
boolean |
<optional> |
Optional default is false. If true wrap the display name in HTML markup. |
Returns:
- Type
- string
Show UI elements associated with the action by setting the hide
property to false.
This is a convenience method to show without having to call actions#lookup and
actions#update.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action to show. | |
pArgs |
object |
<optional> |
An object containing arguments for the action. If the action is bound
to many row or item instances in a report the pArgs property
with the same name as the actions.action idArg property
value is used to determine which UI element to show. |
Example
This example shows the "send-email" action.
apex.actions.show( "send-email" );
Toggle the named action. This should only be used for toggle actions. Toggle actions have get and set methods and don't have a choices property.
This has no effect if the action is hidden or disabled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | Name of the action to toggle. | |
pArgs |
object |
<optional> |
An object containing arguments for the toggle action. The object properties are the argument names and the property values are the argument values. This is passed to the action's get and set functions as the last argument. |
Returns:
- Type
- boolean | undefined
Example
This example toggles the "verbose" action of the context
log1
returned by apex.actions.createContext.
log1.toggle( "verbose" );
Remove callback.
Parameters:
Name | Type | Description |
---|---|---|
pCallback |
function | The function that was added with actions#observe. |
Update any UI elements associated with the action after it changes. Calling update will notify any observers that the action has changed. Debug warnings will be logged and the return value is false if the action has a problem with the shortcut.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pActionName |
string | The name of the action to update. | |
pArgs |
object |
<optional> |
An object containing arguments for the action. If the action is bound
to many row or item instances in a report the pArgs property
with the same name as the actions.action idArg property
value is used to determine which UI element to update. |
Returns:
- Type
- boolean
Example
See example for actions#lookup
Call this only if the set of choices for an action has changed. This will notify any observers that the set of action choices has changed.
Parameters:
Name | Type | Description |
---|---|---|
pActionName |
string | The name of the action that has had its choices updated. |
Returns:
- Type
- boolean
Example
This example adds a new choice to the action "choose-fruit".
var action = apex.actions.lookup( "choose-fruit" );
action.choices.push( {
label: "Apple",
value: "APPLE"
} );
apex.actions.updateChoices( "choose-fruit" );
This is an object that defines the state and behavior of an action. There are 3 kinds of actions:
- action: This is typically associated with a button, link, or action menu item. The action must have an action function or an href URL.
- toggle: This is typically associated with a checkbox input, button, or toggle menu item. The action must have get and set functions and not have a choices property. Toggle actions update an external Boolean state variable by means of the get and set functions. It is also possible to keep the state in the action by using 'this' in the get and set functions.
- radio group: This is typically associated with radio inputs, select list, or a radioGroup menu item. The action must have get and set functions and a choices property. Radio group actions update an external state variable with the currently selected value of the group by means of the get and set functions. It is also possible to keep the state in the action by using 'this' in the get and set functions.
Note: When an action is hidden or disabled the actions#invoke, actions#toggle, and actions#set methods have no effect.
Note: The disabled and hide properties cannot be functions. Menu widget can use actions and non-action based menu items allow hide and disabled to be functions. But when a menu uses an action that action still must not use functions for disabled and hide.
As an alternative to label (or onLabel, offLabel) you can specify labelKey (or onLabelKey, offLabelKey) and the apex.lang.getMessage function will be used to lookup the label text. The localized label text is then stored in the normal label/onLabel/offLabel property. This happens when the action is added. The same applies to titleKey groupKey, and labelKey of each object in the choices array.
Type:
- object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | A unique name for the action. By convention the style of names uses a dash to separate words as in "clear-log". Name must not contain spaces, ">", ":", quote, or double quote, or non-printing characters. | |
idArg |
string |
<optional> |
Only applies when an action handles multiple instances such as when an action is used in a report row or list item. This is the name of the argument that uniquely identifies the bound UI element (button or input element for example) in the row or item. |
instanceSelector |
string |
<optional> |
Only applies when an action handles multiple instances. This is the selector of an ancestor element of the UI element bound to this action. This allows keyboard shortcuts to find the correct instance of the action. |
label |
string | Translatable label for action used in buttons, menus etc. Note: if this is a radio group action (action has choices property) the label is optional. It is used in results of the list and listShortcuts methods. Depending on what kind of UI control the action is bound to it may be used as a label for the whole group. For example using aria-label. | |
onLabel |
string |
<optional> |
Only for dynamic antonyms toggle actions. This is the label when the value is true. |
offLabel |
string |
<optional> |
Only for dynamic antonyms toggle actions. This is the label when the value is false. |
contextLabel |
string |
<optional> |
A more descriptive label used in place of label for use in listing actions and shortcuts. |
icon |
string |
<optional> |
The icon CSS class(es) for action may be used in buttons and menus |
onIcon |
string |
<optional> |
Only for dynamic antonyms toggle actions. This is the icon CSS class(es) to use when the value is true. |
offIcon |
string |
<optional> |
Only for dynamic antonyms toggle actions. This is the icon CSS class(es) to use when the value is false. |
iconType |
string |
<optional> |
The icon type CSS class. Defaults to a-Icon. Updates to the iconType may not be supported by all control types that can be associated with actions. |
disabled |
boolean |
<optional> |
Disabled state of action; true if the action is disabled and false if it is enabled. The default is enabled |
hide |
boolean |
<optional> |
Hidden state of action; true if UI controls connected to this action should be hidden and false otherwise. The default is false (show). |
title |
string |
<optional> |
The title to use as the title attribute when appropriate. |
shortcut |
actions.shortcutName |
<optional> |
The keyboard shortcut to invoke action (not allowed for radio group actions). |
href |
string |
<optional> |
For actions that navigate set href to the URL to navigate to and don't set an action function. An action of type action must have an href or action property set. |
target |
string |
<optional> |
For actions that navigate this is the window to open the href URL in. Only applies when href is specified. Typical value is "_blank" to open in a new tab or window. Omit to open in the current window. |
action |
function |
<optional> |
function(event, focusElement, args):boolean The function that is called when the action is invoked with actions#invoke. The action must return true if it sets focus. An action of type action must have an href or action property set. The args parameter is an optional object argument that can pass in additional data. |
convertBindingArguments |
boolean |
<optional> |
Determines if arguments passed to the
action function are converted. Only applies if this action is expected to
take arguments.
If true then an attempt is made to convert the value of all arguments
to a JavaScript value when the action is invoked by a UI control.
Every attempt is made to convert the argument's string value to a JavaScript value (this includes booleans,
numbers, objects, arrays, and null). A string is only converted to a number if doing so doesn't change its
representation (for example, the string "100" is converted to the number 100, but "1E02" and "100.000" are
left as strings because their numeric value of 100 serializes to "100"). When a string starts with '{' or '[',
then JSON.parse is used to parse it;
it must follow valid JSON syntax including quoted property names.
A string not parseable as a JavaScript value is not converted.
If false then no conversion is done. The default is false. |
get |
function |
<optional> |
function(args):* For toggle actions this function should return true or false. For radio group actions this should return the current value. The args parameter is an optional object argument that can pass in additional data. |
set |
function |
<optional> |
function(value, args) For toggle actions this receives a boolean value. For radio group actions this function receives the new value. The args parameter is an optional object argument that can pass in additional data. |
choices |
Array |
<optional> |
This is only for radio group actions. Array of objects. Each object has properties: label, value, icon, iconType, shortcut, disabled, group (for select lists only) |
labelClasses |
string |
<optional> |
This is only for radio group actions. Classes to add to all radio labels. This and the next two label properties are only used when rendering radio group choices. |
labelStartClasses |
string |
<optional> |
Only for radio group actions. Classes to add to last radio label |
labelEndClasses |
string |
<optional> |
Only for radio group actions. Classes to add to last radio label |
itemWrapClasses |
string |
<optional> |
Only for radio group actions. Classes to add to a span wrapper element. Or to change the
span use one of these prefixes: p:, li:, div:, span: For example "li:myRadio" |
Information about a shortcut.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
shortcut |
string | The shortcut name. |
shortcutDisplay |
string | The shortcut display string. |
actionName |
string | The name of the action that the shortcut invokes. |
actionLabel |
string | The label of the action. For choice actions this includes the choice label. |
This is the string name of a keyboard shortcut. It represents the key(s) to be typed by the user and can be a single key combination or a sequence of keys. The shortcut name must be given in the following format:
[Ctrl+][Alt+][Meta+][Shift+]key
Where strings in square brackets ([]) are optional and represent a modifier key. The string key
is
the name of the key and may be one of: "0"-"9", "A"-"Z" or "Help", "Backspace", "Enter", "Escape",
"Space", "Page Up", "Page Down", "End", "Home", "Left", "Up", "Right", "Down", "Insert", "Delete",
"Keypad 0"-"Keypad 9", "Keypad *", "Keypad +", "Keypad -", "Keypad .", "Keypad /", "Keypad =",
"Keypad Clear", "F1"-"F15",
"Comma", "Period", "Semicolon", "Minus", "Quote", "Backtick", "=", "/", "[", "\", "]".
Order and case is important. Key names and modifiers are not localized. The key names are based on the standard US keyboard layout and may not correspond with what is actually printed on the key caps or what character is printed (in the case of a printing key).
The shortcut name can be a sequence of key combinations separated by commas. The user types the shortcut by typing the first key combination followed by the second and so on. It is possible to have a sequence of length one, which allows defining shortcuts as single letters without any modifier key. Letters can be in upper or lower case.
The primary shortcut for an action is specified in the shortcut property of the actions.action object. This is so that it can be shown in associated menu items. Additional shortcuts can be added with actions#addShortcut.
One limitation of shortcuts in the browser environment is that it is difficult to find keyboard combinations that are not already used for something else and are consistent across all browsers, operating systems and with all keyboard layouts. Key combinations used by the operating system or browser may not be passed on to the actions keydown handler or even if they are the browser or operating system function has also already happened. Many keyboard layouts use the Right side Alt key (known as AltGr) to enter additional characters. The AltGr key can be simulated by pressing Ctrl+Alt. This makes some Ctrl+Alt combinations unavailable. On Mac OS the Option/Alt key plus a letter or number is used to produce additional characters.
See apex.actions.shortcutSupport for information about what kinds of shortcuts if any the user can type. If shortcut support is "off" then no shortcuts are recognized. Shortcut sequences are only recognized if shortcut support is "sequence". Shortcuts can always be defined.
When focus is in a control that allows character input then shortcuts that would produce printable characters or are used for editing are ignored by actions. This includes controls such as text fields and text areas but also controls such as select lists that support type to select.
Type:
- string
Examples
Example key combinations. Press the modifier keys in combination with the specified key: W, F7, Page Down.
Ctrl+W
Ctrl+Shift+F7
Alt+Page Down
Example key sequence. Press the first key combination Ctrl+F2 and release then press the G key and then the H key. For the second example press the C key then the S key. In the third example press C then 6 (not Shift+6). In the last example simply press W. Although the letters must be in upper case in the shortcut name they can be typed with our without the Shift modifier. All but the first example will be ignored when focus is in a control that takes character input.
Ctrl+F2,G,H
C,S
C,6
W