rubengc/cmb2-field-ajax-search

Multiple field forget about limit on refresh

Opened this issue · 0 comments

Hi there,
I just want to discuss a strange problem I met working with this amazin code. I use it frequently but I've noticed a strange behaviour in a new project I am working on.

Basically the first time I set the featured posts all is working great and the limit is respected but when I refresh the page and I hit save again I get my selection added again as you can see from the image below:

fields-added

I've also recorded a short video to show you how the field is behaving. The load spinner is too big but the main issue is that the first time I load the search field I am able to respect my limit but when it gets reloaded I will be able to select new items and if I hit save, even if I do not select anything, the selection increases as in the image above.

The following is the code I am testing and I have this problem in a main option page and also in a WooCommerce Products sub-menu page (this is the reason for the commented lines).

<?php
	$prefix = '_hbeer_';
	
	$hbeer_featured = new_cmb2_box(
		array(
			'id' => $prefix . 'beer_settings',
			'title' => __( 'Scegli birre', 'hbeer-text' ),
			'object_types' => array( 'options-page' ),
			// 'parent_slug' => 'edit.php?post_type=product',
			// 'option_key'   => $prefix . 'fbeers',
		)
	);

	$hbeer_featured->add_field(
		array(
			'name' => __( 'Scegli birre', 'hbeer-text' ),
			'id' => $prefix . 'featured_beers',
			'type' => 'post_ajax_search',
			'multiple' => true,
			'limit' => 6,
			'sortable' => true,
			'query_args' => array(
				'post_type' => [ 'product' ],
				'posts_per_page' => -1,
			),
		)
	);

	cmb2_metabox_form( $prefix . 'beer_settings', 'hbeer-settings' );

Are you able to give me a heads ups on why this is happening? I've recently cloned your repo and changed all the files involved with its use but the problem is still happening.

Thank you in advance for the future help.