Skip to content

Fix chosen fields existing alongside gutenberg #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions js/fieldmanager-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
25 changes: 0 additions & 25 deletions php/class-fieldmanager-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -177,25 +173,4 @@ public function form_data_start_group( $label ) {
public function form_data_end_group() {
return '</optgroup>';
}

/**
* Init chosen.js.
*/
public function chosen_init() {
?>
<script type="text/javascript">
jQuery(function($){
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);
});
</script>
<?php
}
}