Home › Forums › Add-ons › Gallery Field › JavaScript – Gallery Item Remove Click › Reply To: JavaScript – Gallery Item Remove Click
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 ) {
return;
}
/**
* 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 ) {
e.preventDefault();
e.stopPropagation();
let attachment_id = $el.data( 'id' );
if( attachment_id ) {
attachment_id.removeAttachment( attachment_id );
}
/* AJAX to delete the physical attachment. */
};
} )( jQuery );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.