chosen-ajax-addition
chosen-ajax-addition copied to clipboard
Allow custom id/text names
Looks like client expects server to always return
[{id:'', text:''}...]
How to handle a server which returns
[{id:'', name:''}...]
without a custom processItems function just for this?
You are correct sir. Right now there isn't a nice way to specify that.. I can recommend a few work around right now. 1. use the processItems callback. Kinda sucky since you have to go through the array of returned items..
processItems: function(data){
return data.map(function(item) {
return { id: item.id, text: item.name }
});
}
If you can change the server to return [{id:'', text:''}...] or {'id':'text'...}
But I somehow feel that you are raising this issue because you cannot change the server.
- Submit a lovely PR to add two options
optionValuePathandoptionLabelPath. That way you can customize what the keys can be in the result set.
I realize this project hasn't had much love in the recent history. And i've been putting it off since i've been too busy to work on it. I can try to get option 3 working, which in my opinion is the best, but I can't give you a great timeline on when it would be finished. Order of magnitude ... days to weeks?
Thanks for bringing this up! Really useful feature to have.
Thanks Konstantin!
I'm sure you have more important things to focus on. Just pointing out in the docs the return data.map workaround would be great, no need to actually implement new options.
Kind regards and thanks :)