I am using select2 jquery plugin to reformat my long selection options. Everything works as expected, except when I submit the form, the value is idsaved as a value instead of a value (in this case lang). I cannot understand what I am doing wrong.
Here's the script:
var langs=[{id:0,lang:'English'},
{id:1,lang:'Afrikaans'},
{id:2,lang:'Albanian'},
{id:3,lang:'Zulu'}];
function format(item) { return item.lang; };
$("#field_4").select2({
placeholder: "Select your language",
data:{ results: langs, text: 'lang' },
formatSelection: format,
formatResult: format
});
Here's the markup:
<input id="field_4" name="field_4" type="text" class="regular-text " value="3" />
When I register the return value in the console, I see the following:
{Object}
O: Object
id: "1"
text: "Afrikaans"
UPDATE:
. - ( select2), ( id). , <select>, AJAX .
id : function(object) {
return object.lang;
}