31.15 Events

Application Express specific events are discussed in the following section. In most cases you will use Dynamic Actions to respond to browser and APEX specific events. This section is for advanced JavaScript programmers that want to use these events directly from their JavaScript code.

31.15.1 apexafterclosedialog

This event is triggered when an Application Express modal dialog page is closed by either the Dynamic Action Close Dialog action or the Close Dialog process. This is equivalent to the Dialog Closed Dynamic Action event. This event is triggered on the element that opened the dialog.

For buttons it is the button element. For links to dialog pages in lists it is the list region element. For lists used in global top or side navigation or in any other case where the triggering element cannot be determined the event is triggered on the document apex.gPageContext$. The event handler receives an object argument with these properties.

Table 31-81 apexafterclosedialog

Property Type Description

dialogPageId

String

The page number of the dialog page that closed.

*

String

For each page item listed in the Close Dialog process or dynamic action setting Items to Return there is a property with the same name as the item. The value is the value of the item.

Note:

This event is triggered in the parent or calling page not in the modal dialog page. If you want to know when the dialog is closed regardless of how it is closed use the jQuery UI dialogclose event.

Example

This example refreshes the region with static id emp when any modal dialog page closes.

apex.gPageContext$.on( "apexafterclosedialog", function( event, data ) {
    apex.region( "emp" ).refresh();
});

31.15.2 apexafterrefresh

This event is triggered by a number of page or column items just after they are refreshed with new content or data from the server. It is equivalent to the Dynamic Action event After Refresh. Specifically any item that supports the Cascading LOV Parent Item(s) attribute should trigger this event. This event can also be triggered by the apex.server.plugin and apex.server.process APIs if the refreshObject option is provided. The event is triggered on the item element or the element given by the refreshObject. The event handler receives the data given in refreshObjectData if any.

Example

This example disables the button with static id B1 while any refresh is in progress.

apex.jQuery( "body" ).on( "apexbeforerefresh", function() {
    apex.jQuery( "#B1" ).prop( "disabled", true);
}).on( "apexafterrefresh", function() {
    apex.jQuery( "#B1" ).prop( "disabled", false);
});

See Also:

"apex.server namespace"

31.15.3 apexbeforerefresh

This event is triggered by a number of page or column items just before they are refreshed with new content or data from the server. It is equivalent to the Dynamic Action event Before Refresh. Specifically any item that supports the Cascading LOV Parent Item(s) attribute should trigger this event. This event can also be triggered by the apex.server.plugin and apex.server.process APIs if the refreshObject option is provided. The event is triggered on the item element or the element given by the refreshObject. The event handler receives the data given in refreshObjectData if any.

Example

This example disables the button with static id B1 while any refresh is in progress.

apex.jQuery( "body" ).on( "apexbeforerefresh", function() {
    apex.jQuery( "#B1" ).prop( "disabled", true);
}).on( "apexafterrefresh", function() {
    apex.jQuery( "#B1" ).prop( "disabled", false);
});

See Also:

"apex.server namespace"

31.15.4 apexbeforepagesubmit

This event is triggered when the page is submitted with apex.submit or apex.confirm. This includes buttons with action Submit Page and Dynamic Action Submit Page action. It is equivalent to the Dynamic Action event Before Page Submit. It is triggered before the page is validated. It is triggered on apex.gPageContext$, which is the document for Desktop UI pages and the page div for jQuery Mobile UI pages. This event can be canceled by a Dynamic Action Confirm or Cancel Event action so you cannot rely on the page actually being submitted. If you need code to run just before the page is actually submitted see the apexpagesubmit event.

The event handler should not do any long running or asynchronous processing. Specifically it should not make a synchronous or asynchronous Ajax request. The event handler receives a string argument that is the request value.

Example

This example performs an extra validation on page item P1_CHECK_ME. For this to work the Submit button Execute Validations attribute must be Yes and the application compatibility mode must be greater than or equal to 5.1 or the validate option to apex.submit or apex.confirm must be true.

apex.jQuery( apex.gPageContext$ ).on( "apexbeforepagesubmit", function() {
    var item = apex.item("P1_CHECK_ME" ),
        value = item.getValue();
    if ( value !== "valid" ) { // replace with desired constraint check
        item.node.setCustomValidity( "Text field needs to be valid" );
    }else {
        item.node.setCustomValidity( "" );
    }
});

See Also:

"apexpagesubmit"

31.15.5 apexbeginrecordedit

This event is triggered when a region that supports column items such as Interactive Grid begins editing a record. In general it is simpler to use a Dynamic Action on a column item and set attribute Fire on Initialization to Yes. This is equivalent to the Interactive Grid Row Initialization Dynamic Action event.

It is triggered on the widget that is doing the editing. It is triggered after all the column items have been initialized. The event handler receives an object argument with these properties.

Table 31-82 apexbeginrecordedit

Property Type Description

recordId

String

The value of the primary key column. If there is more than one primary key then this is a serialized JSON array of primary key values.

model

Model

The model used by the region widget.

record

Array | Object

The current record being edited. The record belongs to the model given in property model and should only be modified using the model API.

Note:

using the model or record requires using the undocumented apex.model API.

Example

This example responds to the apexbeginrecordedit event of an Interactive Grid, which edits the EMP table. The region was given a static id of emp. The SAL column was given a static id of c_sal.

apex.region( "emp" ).widget().on( "apexbeginrecordedit", function( event, data ) {
    var salary = apex.item( "c_sal" ).getValue();
     // use data.recordId or access any of the column items using apex.item API });

31.15.6 apexendrecordedit

This event is triggered when a region that supports column items such as Interactive Grid ends editing a record.

It is triggered on the widget that is doing the editing. It is triggered after all the model has been updated with any column item changes and the column items have been validated. The event handler receives an object argument with these properties.

Table 31-83 apexendrecordedit

Property Type Description

recordId

String

The value of the primary key column. If there is more than one primary key then this is a serialized JSON array of primary key values.

model

Model

The model used by the region widget.

record

Array | Object

The current record being edited. The record belongs to the model given in property model and should only be modified using the model API.

Note:

using the model or record requires using the undocumented apex.model API.

Example

This example responds to the apexendrecordedit event of an Interactive Grid, which edits the EMP table. The region was given a static id of emp. The SAL column was given a static id of c_sal.

apex.region( "emp" ).widget().on( "apexendrecordedit", function( event, data ) {
    var salary = apex.item( "c_sal" ).getValue();
     // use data.recordId or access any of the column items using apex.item API });

31.15.7 apexpagesubmit

This event is triggered when the page is submitted with apex.submit or apex.confirm. This includes buttons with action Submit Page and Dynamic Action Submit Page action. It is triggered after the page is validated. It is triggered on apex.gPageContext$, which is the document for Desktop UI pages and the page div for jQuery Mobile UI pages. This event is the last chance to set or modify page items before the page is submitted.

The event handler should not do any long running or asynchronous processing. Specifically it should not make a synchronous or asynchronous Ajax request. The event handler receives a string argument that is the request value.

Example

This example makes the page item P1_VALUE upper case before the page is submitted.

apex.jQuery( apex.gPageContext$ ).on( "apexpagesubmit", function() {
    var item = apex.item("P1_VALUE");
    item.setValue( item.getValue().toUpperCase());
});

31.15.8 apexwindowresized

This event is triggered on the window a couple hundred milliseconds after the window stops resizing. Listen for this event to adjust or resize page content after the window is done resizing. In some cases this is a better alternative to the window resize event, which is triggered many times as the window is being resized, because it is triggered just once after the window stops resizing.

Example

This example responds to the apexwindowresized event and updates page content based on the new height and width.

apex.jQuery( window ).on( "apexwindowresized", function( event ) {
    var window$ = apex.jQuery( this ),
          height = window$.height(),
          width = window$.width();
    // update page content based on new window height and width
});