Select2 - Multiple
Select2 - Multiple
I've got a select2 list, using the multiple option. When editing a row Editor doesn't pre-populate the field with all the required values associated to this row.
Even if we try it manually upon opening the Editor form, by copying the example from the official site.
(https://select2.github.io/examples.html#programmatic-control)
$(".js-programmatic-multi-set-val").on("click", function () { $exampleMulti.val(["CA", "AL"]).trigger("change"); });
Our version
var country_locs = movement_contracts_table.row({selected: true}).data()['country_locations[]'];
movement_contracts_editor.field('contract_locations[].country_location_id').inst().select2().val(country_locs).trigger("change");
The Json sent on initial load: (Some ommitted)
{
"data":[
{
"DT_RowId":"row_2",
"main_table":{
"field_1":2,
"field_2":null
},
"country_locations[]":[
3
],
},
{
"DT_RowId":"row_3",
"main_table":{
"field_1":3,
"field_2":null
},
"country_locations[]":[
2
],
}
],
"options":{
"contract_locations[].country_location_id":[
{
"value":2,
"label":"C Refinery - (133)"
},
{
"value":1,
"label":"CT Terminal - (130)"
},
{
"value":3,
"label":"N Refinery - (661)"
}
]
}
}
Is there something we're doing wrong or, is it not possible to programmatically select multiple options in a select2 list?
Answers
bump?