Support

Account

Home Forums Backend Issues (wp-admin) Allow select2 fields to render HTML again Reply To: Allow select2 fields to render HTML again

  • When updated to:

    <script>
      acf.add_filter('select2_args', function(args) {
        args.templateSelection = function(selection) {
          var $selection = jQuery('<span class="acf-selection"></span>');
    
          $selection.html(acf.escHtml(selection.text));
          $selection.data('element', selection.element);
    
          return $selection;
        }
    
        args.templateResult = function(selection) {
          var $selection = jQuery('<span class="acf-selection"></span>');
    
          $selection.html(acf.escHtml(selection.text));
          $selection.data('element', selection.element);
    
          return $selection;
        }
    
        return args;
      });
    </script>

    I renders both the selected value HTML and the HTML in the search result template (if you have HTML there also – like I have to allow icon selection)