Databases Reference
In-Depth Information
initItem: function(apexThis) {
var uiw = this;
The each method is used to loop though the various affected elements. In each case, a local variable
is declared to cache the selection of this which represents the current element in the loop. Again, this is
done to allow for future references to the object via closure.
apexThis.affectedElements.each(function() {
var $this = $(this);
The current value of the element is stored using the data method of jQuery. Note that $v is used to
get the value. Afterward, an event handler is bound to the change event of the element that will update
the saved value if the value changes. Finally, an event handler is bound to the custom apexafterrefresh
event. This last event handler simply calls another method of the widget to restore the value and passes
it a reference to the element that should be restored.
$this
.data('value-saved', $v($this.attr('id')))
.bind('change', function() {
$this.data('value-saved', $v($this.attr('id')));
})
.bind('apexafterrefresh', function() {
uiw. restoreValue($this);
});
});
},
The restoreValue function restores the value of the element passed in using the value last stored via
the data method. Notice that $s is used to set the value of the element.
restoreValue: function($affectedElement) {
$s($affectedElement.attr('id'), $affectedElement.data('value-saved'));
}
});
})(apex.jQuery);
At this point you should be able to set up a test page to see the dynamic action in action. As it
stands, the plug-in would only work with cascading select lists. To make the plug-in more useful,
consider modifying it to support other item types that use LOVs, such as check boxes and radio buttons.
Listing 11-2. PL/SQL Code for the Save Value on Cascade Plug-in
FUNCTION save value render (
p dynamic action IN APEX PLUGIN.T DYNAMIC ACTION,
p plugin IN APEX PLUGIN.T PLUGIN
)
RETURN APEX PLUGIN.T DYNAMIC ACTION RENDER RESULT
IS
Search WWH ::




Custom Search