Object Custom Select Dropdown
Object Custom Select Dropdown
btree
Posts: 99Questions: 14Answers: 11
in Bug reports
Hi,
I want to use a custom values for a dropdown but an object does not work. The problem are the outer [..] from the object.
Field Code:
{
label: i18n.gettext("Apiary:"),
name: 'movedate.apiary_id',
type: 'select',
options: apiary_dropdown('table_dropdown')
},
Object Function:
var obj = {};
$.each(e,function(key, value) //GET EACH OBJECT
{
obj[value.name]=value.id;
});
console.log(obj);
return obj;
Don't work
options: [{Home: "500", test2: "501"}]
Work:
options: {Home: "500", test2: "501"}
Cheers
Hannes
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You have not talked about what software and versions, so I'm guessing this is Editor. Check out the docs on the select field type.
http://editor.datatables.net/reference/field/select
From the docs, when using an array of objects, the field labels need to be in the objects. I can' tell from your code, but I'm going to guess that those are key/value pairs. So:
The first will work if you have an object for each item you want to appear and use the
optionsPair
option for the field type to specify what parameters you should use. however, if your array only has a single item in it, I would suggest simply getting the object (i.e.myArray[0]
) rather than passing in an array that isn't used.Allan
Hi,
first thanks for the quick answers but I cant follow you.
In the documentation it says:
With my understanding my above code should work, also when i copy and paste the console log into the option it works.
edit tried an array like ThomD said, also dont work for me?
Cheers
Hannes
First we need to determine what your data structure looks like. Do you have an array of multiple objects, or an array with just a single object that has lots of key values in it?
Can you link to the page so we can debug it directly please?
Allan
Hi,
could fix it myself. Was good to take a day off programming. I use a ajax call for the return data and didnt though about async and that the return object is not defined.
Now i wrap the code into a $.when....done function and populate the select with update.
Thanks again for all the help and advices!
Great Support
Cheers Hannes