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

Bug when field is on CMB2 Group Field #18

Open
alexis-magina opened this issue May 3, 2017 · 8 comments
Open

Bug when field is on CMB2 Group Field #18

alexis-magina opened this issue May 3, 2017 · 8 comments

Comments

@alexis-magina
Copy link
Owner

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

@tsabedin
Copy link

tsabedin commented Dec 25, 2017

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

@sebastillar
Copy link

Any solution to this bug?

@jmarx
Copy link

jmarx commented Nov 16, 2018

Bump

@jmarx
Copy link

jmarx commented Nov 16, 2018

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

@yuriy-dev
Copy link

Looks like it still is not fixed

@osimagina
Copy link

Something new about this issue ????

@dawnbirth
Copy link

dawnbirth commented Jun 16, 2020

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);
					}
				}

@taarnfalk
Copy link

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.

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

8 participants