cmb2-field-post-search-ajax icon indicating copy to clipboard operation
cmb2-field-post-search-ajax copied to clipboard

Bug when field is on CMB2 Group Field

Open alexis-magina opened this issue 7 years ago • 8 comments

JS Error and save issue when field is used in a cmb2 group

alexis-magina avatar May 03 '17 13:05 alexis-magina

In cmb2 group autocomplete works on first entry only, from second entry it do not works. Even multiple select do not works

tsabedin avatar Dec 25 '17 20:12 tsabedin

Any solution to this bug?

sebastillar avatar Jul 29 '18 17:07 sebastillar

Bump

jmarx avatar Nov 16 '18 02:11 jmarx

I'm assuming that no one has found a fix to this issue yet?

jmarx avatar Nov 16 '18 20:11 jmarx

Looks like it still is not fixed

yuriy-dev avatar Feb 06 '19 14:02 yuriy-dev

Something new about this issue ????

osimagina avatar Sep 30 '19 11:09 osimagina

This JS issue can be fixed like this In the file "js/mag-post-search-ajax.js" Replace this part

				onSelect: function (suggestion) {
					$(this).devbridgeAutocomplete('clearCache');
					var lid 	 = $(this).attr('id') + '_results';
					var limit 	 = $(this).attr('data-limit');
					var sortable = $(this).attr('data-sortable');
					if( limit > 1 ){
						var handle = (sortable == 1) ? '<span class="hndl"></span>' : '';				
						$('#'+lid).append('<li>'+handle+'<input type="hidden" name="'+lid+'[]" value="'+suggestion.data+'"><a href="'+suggestion.guid+'" target="_blank" class="edit-link">'+suggestion.value+'</a><a class="remover"><span class="dashicons dashicons-no"></span><span class="dashicons dashicons-dismiss"></span></a></li>');
						$(this).val('');
						if( limit === $('#' + lid + ' li').length ){
							$(this).prop( 'disabled', 'disabled' );
						}
						else{
							$(this).focus();
						}
					}
					else{
						$('input[name='+lid+']').val(suggestion.data);
					}
				}

With this

				onSelect: function (suggestion) {
					$(this).devbridgeAutocomplete('clearCache');
					var lid 	  = $(this).attr('id') + '_results';
					var limit 	  = $(this).attr('data-limit');
					var sortable  = $(this).attr('data-sortable');
					var resultsContainer = $(document.getElementById(lid));
					if( limit > 1 ){
						var handle = (sortable == 1) ? '<span class="hndl"></span>' : '';
						resultsContainer.append('<li>'+handle+'<input type="hidden" name="'+lid+'[]" value="'+suggestion.data+'"><a href="'+suggestion.guid+'" target="_blank" class="edit-link">'+suggestion.value+'</a><a class="remover"><span class="dashicons dashicons-no"></span><span class="dashicons dashicons-dismiss"></span></a></li>');
						$(this).val('');
						if( limit === resultsContainer.find('li').length ){
							$(this).prop( 'disabled', 'disabled' );
						}
						else{
							$(this).focus();
						}
					}
					else{
						$('input[name='+lid+']').val(suggestion.data);
					}
				}

dawnbirth avatar Jun 16 '20 13:06 dawnbirth

Just want to say thanks for the plugin. I need this to lookup in a custom table. Had a problem when you use this field in a group. The devbridgeAutocomplete did not run for added row.

I changed the render function. Added $field_id here (line45) /** * Render field */ public function render( $field, $value, $object_id, $object_type, $field_type ) { $this->setup_admin_scripts(); $field_name = $field->_name(); $field_id = $field->id();

and changed this (line 87) from $field_name to $field_id : echo $field_type->input( array( 'type' => 'text', 'name' => $field_name, 'id' => $field_id, 'class' => 'cmb-post-search-ajax',

I just want this field in a group so I changed the js to this : $('.cmb-repeatable-grouping').on('click', '.cmb-post-search-ajax', function(){

I have not tested if it save to database. I'm using a form to create a custom post so I do not need to save.

taarnfalk avatar Jun 18 '20 16:06 taarnfalk