File Upload - Binding Events - Multiple data-uploader's

Support General File Upload - Binding Events - Multiple data-uploader'sResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #44620
    CodogCodog
    Participant

    Hi there,
    I have a file_upload field where users can upload multiple files. I also use your suggested jQuery binding events method to trigger various feedback to the user like this:

    jQuery( function( $ ){
        setTimeout( function() {
            const myUploader =  $( 'input.rwmb-file_upload.rwmb-media' ).data( 'uploader' );
    
            myUploader.uploader.bind( 'FileUploaded', function( up, file, res ) {
                // Do some stuff
            } );
    
            myUploader.uploader.bind('UploadProgress', function (up, file) {
               // Do some stuff
            } );
    
            myUploader.uploader.bind('FilesAdded', function (up, file) {
               // Do some stuff
            } );
    
        }, 1000 );
    } );

    All works fine!

    However, this methodology fails when there are multiple file_upload custom field instances on the same page. IE: I have one instance for just a featured image and another instance for an image gallery.

    Q) How or what is considered the correct method to target multiple file_upload instances on the same page via jQuery? The const myUploader = $( 'input.rwmb-file_upload.rwmb-media' ).data( 'uploader' ); only targets a single instance right?

    I look forward to your response 🙂

    #44625
    PeterPeter
    Moderator

    Hello,

    You can select a specific field ID with this code:

    const myUploader =  $( 'input.rwmb-file_upload.rwmb-media[name="file_upload_2"' ).data( 'uploader' );
    

    where file_upload_2 is the field ID.

    #44645
    CodogCodog
    Participant

    Thanks Peter,
    thats great!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.