diff --git a/cmb2-field-ajax-search.php b/cmb2-field-ajax-search.php index e09b020..112d59e 100644 --- a/cmb2-field-ajax-search.php +++ b/cmb2-field-ajax-search.php @@ -27,7 +27,7 @@ if( ! class_exists( 'CMB2_Field_Ajax_Search' ) ) { /** * Current version number */ - const VERSION = '1.0.2'; + const VERSION = '1.0.3'; /** * Initialize the plugin by hooking into CMB2 @@ -116,8 +116,8 @@ if( ! class_exists( 'CMB2_Field_Ajax_Search' ) ) { echo $field_type->input( array( 'type' => 'text', - 'name' => $field->_name() . '_input', - 'id' => $field_name . '_input', + 'name' => '_' . $field->_name(), + 'id' => $field_name, 'class' => 'cmb-ajax-search cmb-' . $object_to_search . '-ajax-search', 'value' => $input_value, 'desc' => false, diff --git a/js/ajax-search.js b/js/ajax-search.js index aa2e9b2..41de292 100644 --- a/js/ajax-search.js +++ b/js/ajax-search.js @@ -3,7 +3,7 @@ $('.cmb-ajax-search:not([data-ajax-search="true"])').each(function () { $(this).attr('data-ajax-search', true); - var field_id = $(this).attr('id').replace( new RegExp('_input$'), '' ).replace(/[\[\]']+/g, '_'); // Field id, the true one field + var field_id = $(this).attr('id').replace(/[\[\]']+/g, '_'); // Field id, the true one field var object_type = $(this).attr('data-object-type'); var query_args = $(this).attr('data-query-args'); @@ -50,17 +50,17 @@ onSelect: function ( suggestion ) { $(this).devbridgeAutocomplete('clearCache'); - var field_name = $(this).attr('name').replace( new RegExp('_input$'), '' ); + var field_name = $(this).attr('name'); var multiple = $(this).attr('data-multiple'); var limit = parseInt( $(this).attr('data-limit') ); var sortable = $(this).attr('data-sortable'); - var field_name_temp = field_name.replace( /[\[\]']+/g, '_' ); + var field_name_temp = field_name.substring(1).replace( /[\[\]']+/g, '_' ); if( multiple == 1 ) { // Multiple $('#' + field_name_temp + '_results' ).append( '
  • ' + ( ( sortable == 1 ) ? '' : '' ) + - '' + + '' + '' + suggestion.value + '' + '' + '
  • ' ); diff --git a/readme.md b/readme.md index 6f5b4a0..55d6c5e 100644 --- a/readme.md +++ b/readme.md @@ -62,7 +62,7 @@ function cmb2_ajax_search_metabox() { 'desc' => __( 'Field description (optional)', 'cmb2' ), 'id' => $prefix . 'posts', 'type' => 'post_ajax_search', - 'multiple' => true, + 'multiple-item' => true, 'limit' => 10, 'query_args' => array( 'post_type' => array( 'post', 'page' ), @@ -88,7 +88,7 @@ function cmb2_ajax_search_metabox() { 'desc' => __( 'Field description (optional)', 'cmb2' ), 'id' => $prefix . 'users', 'type' => 'user_ajax_search', - 'multiple' => true, + 'multiple-item' => true, 'limit' => 5, 'query_args' => array( 'role__not_in' => array( 'Administrator', 'Editor' ), @@ -113,7 +113,7 @@ function cmb2_ajax_search_metabox() { 'desc' => __( 'Field description (optional)', 'cmb2' ), 'id' => $prefix . 'terms', 'type' => 'term_ajax_search', - 'multiple' => true, + 'multiple-item' => true, 'limit' => -1, 'query_args' => array( 'taxonomy' => 'post_tag', @@ -156,6 +156,12 @@ If multiple == true will return an array of IDs of attached object: ## Changelog +### 1.0.3 + +* Fixed issues with repeatable fields +* Removed unused code +* Moved to new paramenter `multiple-item` to avoid conflicts with CMB2 + ### 1.0.2 * Updated devbridgeAutocomplete lib