Home Forums Add-ons Gallery Field JavaScript – Gallery Item Remove Click


JavaScript – Gallery Item Remove Click

  • Hello,

    I’m trying to trigger a JS event whenever a gallery item is removed. I’ve tried:

    $( document ).on( 'click', '.acf-gallery-remove', function() { console.log( 'here' ); } );

    The above code snippet never triggers. I see that on the field model it has the following event set:

    'click .acf-gallery-remove': 'onClickRemove'

    Is there a way to get in the middle of that callback or override that callback? I’m just looking to trigger a single event whenever the button is clicked to remove a gallery item.

  • If there’s a better way to do this, let me know. This is how I was able to do it:

    ( function( $ ) {
    	if( 'object' !== typeof acf ) {
    	 * Override Gallery Field onClickRemove method.
    	 * This method removes the attachment from the galllery but not the server.
    	 * Runs on media [x] click and "Remove" in gallery sidebar.
    	 * @param e Event
    	 * @param $el DOMObject
    	 * @return void
    	acf.models.GalleryField.prototype.onClickRemove = function( e, $el ) {
    		let attachment_id = $ 'id' );
    		if( attachment_id ) {
    			attachment_id.removeAttachment( attachment_id );
    		/* AJAX to delete the physical attachment. */
    } )( jQuery );
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.