Added autocomplete options hook

This commit is contained in:
Ko Takagi 2019-02-09 12:29:15 +09:00
parent 973308f0be
commit b00b91ec85
2 changed files with 6 additions and 4 deletions

View File

@ -188,7 +188,8 @@ if( ! class_exists( 'CMB2_Field_Ajax_Search' ) ) {
wp_localize_script( 'cmb-ajax-search', 'cmb_ajax_search', array( wp_localize_script( 'cmb-ajax-search', 'cmb_ajax_search', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ), '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' ); wp_enqueue_script( 'cmb-ajax-search' );

View File

@ -8,7 +8,7 @@
var object_type = $(this).attr('data-object-type'); var object_type = $(this).attr('data-object-type');
var query_args = $(this).attr('data-query-args'); var query_args = $(this).attr('data-query-args');
$(this).devbridgeAutocomplete({ $(this).devbridgeAutocomplete(Object.assign({
serviceUrl: cmb_ajax_search.ajaxurl, serviceUrl: cmb_ajax_search.ajaxurl,
type: 'POST', type: 'POST',
triggerSelectOnValidInput: false, triggerSelectOnValidInput: false,
@ -78,7 +78,8 @@
$('input[name=' + field_name + ']').val( suggestion.id ).change(); $('input[name=' + field_name + ']').val( suggestion.id ).change();
} }
} }
}); },
cmb_ajax_search.options));
if( $(this).attr('data-sortable') == 1 ){ if( $(this).attr('data-sortable') == 1 ){
$('#' + field_id + '_results').sortable({ $('#' + field_id + '_results').sortable({
@ -116,4 +117,4 @@
$(this).remove(); $(this).remove();
}); });
}); });
})(document, jQuery); })(document, jQuery);