diff --git a/js/fieldmanager-select.js b/js/fieldmanager-select.js index 83d07e4e6d..8ab5419b79 100644 --- a/js/fieldmanager-select.js +++ b/js/fieldmanager-select.js @@ -101,6 +101,21 @@ function fm_select_init() { } +function chosen_init() { + if ( $( '.chosen-select' ).length ) { + var chosenOpts = { + allow_single_deselect: true, + disable_search_threshold: -1, + width: '350px' + }; + $( '.fm-wrapper' ).on( 'fm_added_element fm_collapsible_toggle fm_activate_tab', '.fm-item', function() { + $( '.chosen-select:visible', this ).chosen( chosenOpts ) + }); + $( '.chosen-select:visible' ).chosen( chosenOpts ); + } +} + fmLoadModule( fm_select_init ); +fmLoadModule( chosen_init) ; } )( jQuery ); diff --git a/php/class-fieldmanager-select.php b/php/class-fieldmanager-select.php index 87efd826b0..bf13e66171 100644 --- a/php/class-fieldmanager-select.php +++ b/php/class-fieldmanager-select.php @@ -106,10 +106,6 @@ public function form_element( $value = array() ) { // Handle type-ahead based fields using the chosen library. if ( $this->type_ahead ) { $select_classes[] = 'chosen-select'; - if ( ! isset( $GLOBALS['fm_chosen_initialized'] ) ) { - add_action( 'admin_footer', array( $this, 'chosen_init' ) ); - $GLOBALS['fm_chosen_initialized'] = true; - } if ( $this->grouped ) { $select_classes[] = 'fm-options-grouped'; @@ -177,25 +173,4 @@ public function form_data_start_group( $label ) { public function form_data_end_group() { return ''; } - - /** - * Init chosen.js. - */ - public function chosen_init() { - ?> - -