slim-select
slim-select copied to clipboard
How to make `addable` wait?
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?
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: ....,
}));
}
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.