slim-select icon indicating copy to clipboard operation
slim-select copied to clipboard

How to make `addable` wait?

Open heraldofsolace opened this issue 3 years ago • 1 comments

I have a slim-select field for adding categories to a post. When the user click on the add button, I want to display a modal where they can add a new category which will then be added to the select. Here is what I have so far -

addable: function(value) {
    modal.show()
    // Form is a form inside the modal to add the new category
    form.addEventListener("submit", function(e){
        Rails.ajax({
            ...,
            success: function(response) {
                 // Want to return from here
                 return { value: response.id, text: response.name }
            }
        })
    })
} 

Clearly it doesn't work as I have to return from the addable function. Any idea what should be done?

heraldofsolace avatar Apr 25 '21 14:04 heraldofsolace

Did you ever solve this? I'm facing the same issue. Options are never added to slimeselect container.

addable: function (value) {
	addTag(value).then(res => {
		if (res.code == 200) {
			return {
				text: res.text,
				value: res.value
			}
		} else {
			console.log('false');
			return false;
		}
	});
}
function addTag(value) {
	return ($.ajax({
		type: "POST",
		url: "xhr/",
		dataType: "json",
		data: ....,
	}));	
}

ontelo avatar Feb 16 '22 13:02 ontelo

New version of slim select was just released. Not sure if this is still an issue for you. If the new version doesnt fix your issue, let me know and ill see what i can do to help. Thanks.

brianvoe avatar Nov 21 '22 00:11 brianvoe