From b00b91ec851bb8861a4ec211f4d3fcf9f2f86ede Mon Sep 17 00:00:00 2001 From: Ko Takagi Date: Sat, 9 Feb 2019 12:29:15 +0900 Subject: [PATCH] Added autocomplete options hook --- cmb2-field-ajax-search.php | 3 ++- js/ajax-search.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmb2-field-ajax-search.php b/cmb2-field-ajax-search.php index 7765a75..514e542 100644 --- a/cmb2-field-ajax-search.php +++ b/cmb2-field-ajax-search.php @@ -188,7 +188,8 @@ if( ! class_exists( 'CMB2_Field_Ajax_Search' ) ) { wp_localize_script( 'cmb-ajax-search', 'cmb_ajax_search', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), - 'nonce' => wp_create_nonce( 'cmb_ajax_search_get_results' ) + 'nonce' => wp_create_nonce( 'cmb_ajax_search_get_results' ), + 'options' => apply_filters( 'cmb_field_ajax_search_autocomplete_options', array() ) ) ); wp_enqueue_script( 'cmb-ajax-search' ); diff --git a/js/ajax-search.js b/js/ajax-search.js index 3609a44..47d6dce 100644 --- a/js/ajax-search.js +++ b/js/ajax-search.js @@ -8,7 +8,7 @@ var object_type = $(this).attr('data-object-type'); var query_args = $(this).attr('data-query-args'); - $(this).devbridgeAutocomplete({ + $(this).devbridgeAutocomplete(Object.assign({ serviceUrl: cmb_ajax_search.ajaxurl, type: 'POST', triggerSelectOnValidInput: false, @@ -78,7 +78,8 @@ $('input[name=' + field_name + ']').val( suggestion.id ).change(); } } - }); + }, + cmb_ajax_search.options)); if( $(this).attr('data-sortable') == 1 ){ $('#' + field_id + '_results').sortable({ @@ -116,4 +117,4 @@ $(this).remove(); }); }); -})(document, jQuery); \ No newline at end of file +})(document, jQuery);