Skip to content
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

When you open the select post window the previous selected posts aren't selected #30

Open
koffielyder opened this issue Oct 4, 2019 · 6 comments

Comments

@koffielyder
Copy link

If i have let say 2 Posts previously selected and saved they aren't selected in the popup when i click to search again. The same aplies when I select a post and then search (inside the popup) for another post it de-selects the first post

@tw2113
Copy link

tw2113 commented Oct 4, 2019

Can you provide your CMB2 code configuration so that we can attempt to recreate the setup locally and test?

@koffielyder
Copy link
Author

			array(
				'name'        => __('Featured Recipes'),
				'id'          => '_featured_recipes_list',
				'type'        => 'post_search_text', // This field type
				'post_type'   => 'Recept',
				'select_type' => 'select',
				'select_behavior' => 'add'
			)

@tw2113
Copy link

tw2113 commented Oct 7, 2019

Could you post everything as part of the new new_cmb2_box( ... ) onwards? instead of just one field? Just in case some other part is playing a part.

@koffielyder
Copy link
Author

Well im using the cmb2 box as dynamic addable items so its not the conventional setup. here is the code

$cmb = new_cmb2_box(array(
            'id'            => $prefix . 'repeater',
            'title'         => 'Page Layout',
            'object_types'  => array('page', 'nieuws', 'vacature'), // Post type
            'context'       => 'normal',
            'priority'      => 'high',
            'show_names'    => true, // Show field names on the left
        ));
$group_field_id = $cmb->add_field(array(
            'id'          => $prefix . '_repeat_group',
            'type'        => 'group',
            'description' => __('Generates reusable form entries', 'cmb2'),
            'options'     => array(
                'group_title'       => __('Entry {#}', 'cmb2'),
                'add_button'        => __('Add Another Entry', 'cmb2'),
                'remove_button'     => __('Remove Entry', 'cmb2'),
                'sortable'          => true,
            ),

        ));
        $dataArrayWrapper = InitMetaBoxes($group_field_id, $isArchive);

Then I add the array (Im using cmb2-conditionals)

array(
	'name'        => __('Featured Recipes'),
	'id'          => '_featured_recipes_list',
	'type'        => 'post_search_text', // This field type
	'post_type'   => 'Recept',
	'select_type' => 'select',
	'select_behavior' => 'add',
        'attributes' => array(
            'data-conditionals-id' => id,
            'data-conditionals-value' => value
        )
)

$cmb->add_group_field($id, $array);

I have already fixed it for my project by writing custom code in the plugin so it saves the selected values in variables and reads that and checks the correct item on search or reload

@tw2113
Copy link

tw2113 commented Oct 8, 2019

Just for completeness sake, for myself or anyone else wanting to attempt debugging, what do you have for the InitMetaBoxes() function? assuming that's something you can share at the moment.

@koffielyder
Copy link
Author

function InitMetaBoxes($groupFieldId, $isArchive = false)
{
    $dataArrayWrapper = [];
    $dataArrayWrapper[] = $mainContentDataArray = main_content_metabox_data($groupFieldId, 'mainContent');
    $dataArrayWrapper[] = $subContentDataArray = sub_content_metabox_data($groupFieldId, 'subContent');
    $dataArrayWrapper[] = $inlineImagesDataArray = inline_images_metabox_data($groupFieldId, 'inlineImages');
    $dataArrayWrapper[] = $featuredPostDataArray = cmb2_featured_post_metabox_data($groupFieldId, 'featuredPost');
    $dataArrayWrapper[] = $featuredRecipesDataArray = featured_recipes_metabox_data($groupFieldId, 'featuredRecipes');
    $dataArrayWrapper[] = $customPostsDataArray = cmb2_custom_post_data($groupFieldId, 'customPost');
    $dataArrayWrapper[] = $advertisementDataArray = advertisement_metabox_data($groupFieldId, 'ad');
    $dataArrayWrapper[] = $sliderDataArray = text_slider_metabox_data($groupFieldId, 'textSlider');
    $dataArrayWrapper[] = $headerTextbox = header_textbox_metabox_data($groupFieldId, 'headerTextbox');
    $dataArrayWrapper[] = $archiveListDataArray = archive_list_metabox_init($groupFieldId, 'archiveList');
    $dataArrayWrapper[] = $featuredNewsListDataArray = latest_news_metabox_data($groupFieldId, 'featuredNews');
    $dataArrayWrapper[] = $featuredProductsListDataArray = products_featured_metabox_data($groupFieldId, 'featuredProducts');
    $dataArrayWrapper[] = $instagramDataArray = instagram_metabox_data($groupFieldId, 'instagram');
    $dataArrayWrapper[] = $titleCenteredDataArray = title_centered_metabox_data($groupFieldId, 'centeredTitle');
    
    
    return $dataArrayWrapper;
}

InitMetaBoxes() adds all box data for all diffrent types of metaboxes i have created like this

function latest_news_metabox_data($groupId, $filter)
{
    return array(
		'data' =>
		array(
			array(
				'name' => __('Title'),
				'desc' => __(''),
				'id'   => '_featured_news_title',
                'type' => 'text',
                'default' => 'Meer interessant nieuws',
				'attributes'   => array(
					'required'               => TRUE,
				),
            ),	
            array(
                'name' => 'Laatste 4 nieuwsartiekelen',
                'desc' => __('If checked it will show the latest 4 news items otherwise it is user defined', 'msft-newscenter'),
                'id'   => '_latest_news',
                'type' => 'checkbox',
                'attributes' => array(),
            ),
            
            array(
                'name'        => __('Nieuws Berichten'),
                'id'          => '_news_items',
                'type'        => 'post_search_text', // This field type
                // post type also as array
                'post_type'   => ['nieuws'],
                // Default is 'checkbox', used in the modal view to select the post type
                'select_type' => 'select',
                // Will replace any selection with selection from modal. Default is 'add'
                'select_behavior' => 'replace',
                'attributes' => array(
                    'required'				=> FALSE
    
                ),
            ),		
        ),
        
		'selectFilter' => $filter
	);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants