Support

Account

Home Forums Backend Issues (wp-admin) Manipulating Select2 fields

Helping

Manipulating Select2 fields

  • I have an ACF Select field (with Stylized UI set to Yes) that I need to be able to call select2 commands on.
    To gain a reference to the fields I used an acf js filter.

    var $expirationSelect2;
      acf.add_filter('select2_args', function( args, $select, settings ){
        if ( settings.key === "field_57d1ce76b8a84" ) {
          $expirationSelect2 = $select;
        }
        // do something to args
    
        // return
        return args;
    
      });

    From my understanding, this should allow me to later call things like:
    $expirationSelect2.select2("open");

    But nothing works. I know acf has wrapped select2 a bit but I don’t know if that wrapper has an api I should be using instead. Please help.

  • UPDATE: apparently the actual selector is a sibling of the <select> tag.
    $expirationSelect2.siblings('input').select2("open"); appears to work.

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

You must be logged in to reply to this topic.