Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Last active December 20, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardW8k/6071402 to your computer and use it in GitHub Desktop.
Save richardW8k/6071402 to your computer and use it in GitHub Desktop.
for use with Gravity Forms to set options for enhanced ui drop downs, add to theme's functions.php file
// set options for chosen e.g disable search or set width to use percentage
add_action('gform_pre_render','set_chosen_options');
function set_chosen_options($form){
if(wp_script_is('gforms_chosen',$list='queue')){
?>
<script>
gform.addFilter('gform_chosen_options','set_chosen_options_js');
function set_chosen_options_js(options,element){
//options.placeholder_text_single = 'Selectionner une Option'; // set default placeholder for blank first option
//options.search_contains = true; // search options for partial matches
options.max_selected_options = 2; // limit how many options may be chosen in a multi-select
/* options available for use once chosen is updated to 0.9.14 or newer */
//options.disable_search_threshold = 5; // disable search if select has less than 5 options
//options.disable_search = true; // disable search altogether
//options.width = '100%'; // set chosen to use percentage based width
//options.allow_single_deselect = true; // add a UI element to single select box for option deselection, will only work if the first option has blank text
return options;
}
</script>
<?php
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment