The most reliable way I've found to listen for the entry type switching would be to add an ajaxComplete
listener to the document
object, testing the call's URL for the switchEntryType
action handle:
$(document).ajaxComplete(myAjaxCompleteHandler);
function myAjaxCompleteHandler( e, status, requestData )
{
if ( requestData.url.indexOf( 'switchEntryType' ) > -1 ) {
// Entry type switched. Do your stuff!
...
}
}
If you need the new/active entry type's ID after the switch, the easiest way to get that would be by getting the entry type dropdown's value:
var entryTypeId = $( '#entryType' ).val();
Other data, like all the fields and the section ID, is available as part of the requestData
object, specifically as a serialized string under requestData.data
. Here's a very basic deserialization to get to the entry type and section IDs:
var data = {},
params = $.map( unescape( requestData.data ).split( '&' ), function ( param ) {
param = param.split( '=' );
data[ param[ 0 ] ] = param[ 1 ] || null;
} ),
sectionId = parseInt( data.sectionId ),
entryTypeId = parseInt( data.typeId );
}
The field data is more complex – many fields will be arrays which aren't handled well by the above example – but there's several jQuery plugins to help out with that stuff if you need it :)