| @@ -6,15 +6,25 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | function wppb_select2_initialize() { |
| 8 | 8 | jQuery ( '.custom_field_select2' ).each( function(){ |
| 9 | 9 | var selectElement = jQuery( this ); |
| 10 | - var arguments = wp.hooks.applyFilters( 'wppb_select2_initialize_arguments', arguments, selectElement ); | |
| 10 | + var select2Arguments = selectElement.attr( 'data-wppb-select2-arguments' ); | |
| 11 | 11 | |
| 12 | - if ( !( 'placeholder' in arguments ) || arguments.placeholder === '' ) { | |
| 13 | - arguments.placeholder = jQuery('label[for="' + selectElement.attr('id') + '"]').text(); | |
| 12 | + if ( select2Arguments ) { | |
| 13 | + select2Arguments = JSON.parse( select2Arguments ); | |
| 14 | + } else { | |
| 15 | + select2Arguments = {}; | |
| 14 | 16 | } |
| 15 | 17 | |
| 16 | - selectElement.select2( arguments ).on('select2:open', function(){ | |
| 18 | + select2Arguments = wp.hooks.applyFilters( 'wppb_select2_initialize_arguments', select2Arguments, selectElement ); | |
| 19 | + | |
| 20 | + // On a multiple select the placeholder lands in the inline search box, which is only as | |
| 21 | + // wide as the free space left by the selected options, so the field title gets truncated. | |
| 22 | + if ( !selectElement.prop( 'multiple' ) && ( !( 'placeholder' in select2Arguments ) || select2Arguments.placeholder === '' ) ) { | |
| 23 | + select2Arguments.placeholder = jQuery('label[for="' + selectElement.attr('id') + '"]').text(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + selectElement.select2( select2Arguments ).on('select2:open', function(){ | |
| 17 | 27 | // compatibility with Divi Overlay |
| 18 | 28 | if( jQuery(selectElement).parents( '.overlay-container' ).length ){ |
| 19 | 29 | jQuery(selectElement).data('select2').dropdown.$dropdownContainer.css( 'z-index', '99999999' ); |
| 20 | 30 | } |