# profile-builder/3.16.0/front-end/default-fields/select2/select2.js

User Profile Builder – Beautiful User Registration Forms, User Profiles &amp; User Role Editor, version 3.16.0. 27 lines.

- Page: https://pluginprobe.com/plugins/profile-builder/3.16.0/code/front-end/default-fields/select2/select2.js
- Raw: https://pluginprobe.com/plugins/profile-builder/3.16.0/raw/front-end/default-fields/select2/select2.js
- Modified: 2025-03-31T08:31:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/profile-builder/3.16.0/code/front-end/default-fields/select2/select2.js#L10-L20`.

```javascript

/**
 * Function that initializes select2 on fields
 *
 * @since v.3.3.4
 */
function wppb_select2_initialize() {
    jQuery ( '.custom_field_select2' ).each( function(){
        var selectElement = jQuery( this );
        var arguments = wp.hooks.applyFilters( 'wppb_select2_initialize_arguments', arguments, selectElement );

        if ( !( 'placeholder' in arguments ) || arguments.placeholder === '' ) {
            arguments.placeholder = jQuery('label[for="' + selectElement.attr('id') + '"]').text();
        }

        selectElement.select2( arguments ).on('select2:open', function(){
            // compatibility with Divi Overlay
            if( jQuery(selectElement).parents( '.overlay-container' ).length ){
                jQuery(selectElement).data('select2').dropdown.$dropdownContainer.css( 'z-index', '99999999' );
            }
        });
    });
}

jQuery( document ).ready(function() {
    wppb_select2_initialize();
});
```
