bootstrap-suggest icon indicating copy to clipboard operation
bootstrap-suggest copied to clipboard

map: not working with ajax

Open jayant-lumino opened this issue 3 years ago • 3 comments

Hi, First of all, thank you for this awesome plugin. when I am using your plugin with prefetched data then it is working fine. Showing all the result

`$('.short_code').suggest('#', {
data: text_shortcuts_array,
map: function(text_shortcut) {
	return {
		value: text_shortcut.text,
		text: '<strong>'+text_shortcut.value+'</strong><br>'
	}
},
})`


But when I am using ajax for data things are not working fine for me. I don't know where I am doing wrong

$('.short_code').suggest('#', {
data: function(q, provide) {
	$.getJSON("/someurl", { q: q }, function(data) {

		text_shortcuts = data;
		var text_shortcuts_array = [];

		$.each(text_shortcuts, function (key, value) {
			text_shortcuts_array.push({
				value: value['Textshortcut']['shortcut'],
				text: value['Textshortcut']['text']
			});
		})
		<!-- I am getting value here -->
provide.call(text_shortcuts_array);
	});

},
map: function(text_shortcut) {
	return {
		value: text_shortcut.text,
		text: '<strong>'+text_shortcut.value+'</strong><br>'
	}
},
})`
```

jayant-lumino avatar Mar 16 '21 13:03 jayant-lumino

"Add delay search while typing" is not working. When I integrate as per the instruction, dropdown box is not showing

fawwadshafi avatar Nov 09 '21 12:11 fawwadshafi

Also, there is another issue. If we do not use "Delay" then "map" function is not loading getting the Latest records from ajax

fawwadshafi avatar Nov 09 '21 12:11 fawwadshafi

For what it's worth, I too had trouble with the provide.call() method. But I was able to get it to work by returning a jqXHR promise. So if you need to do some post-processing of the ajax response, you might try wrapping the $.getJSON() call in a JQuery promise, then resolving the promise after post-processing the ajax data.

shaneiseminger avatar Jan 09 '22 23:01 shaneiseminger