cmb2-field-post-search-ajax
cmb2-field-post-search-ajax copied to clipboard
Bug when field is on CMB2 Group Field
JS Error and save issue when field is used in a cmb2 group
In cmb2 group autocomplete works on first entry only, from second entry it do not works. Even multiple select do not works
Any solution to this bug?
Bump
I'm assuming that no one has found a fix to this issue yet?
Looks like it still is not fixed
Something new about this issue ????
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);
}
}
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.