Support

Account

Home Forums Backend Issues (wp-admin) JavaScript events on Select2 elements

Solved

JavaScript events on Select2 elements

  • I’m trying to hook into events fired by Select2 elements but I’m unsure which element within the ACF markup should be targeted.

    acf.add_action('append', function( $el ){
    	var $wood = $el.find( '[data-name="bulk_wood"] input');
    	$wood.focus();
    	$wood.select2('open');
    
    	$wood.on('select2:close', function(e) {
    		console.log('close event');
    	});
    });

    With the above code, the Select2 select element is focused and opened successfully, but fails to trigger an event when it closes.

    How do I hook into the Select2 events?

  • Hi @andrew-fleming ,

    I have little experience with the select2 plugin but from their documentation, the close event should have the following format

    .on("select2-close", function () {});

    I hope this helps.

  • Yep, you’re right @acf-support . I was following the docs for the latest version of Select2 instead of the version in use by ACF.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘JavaScript events on Select2 elements’ is closed to new replies.