Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82219

Select2 - Selected value is empty on dropdown open

$
0
0

Hi, I have ad editor with this field:

{label: "Lunghezza", name: 'lunghezza', data: "lunghezza", type:'select2', options: [], opts: {"tags": true}},

The options are populated on init:

editor_detail.on( 'initEdit', function ( e, node, data, items, type ) {
    getListaLunghezze(data['id_particolare']);
  });


function getListaLunghezze(id_particolare){
  var lista_lunghezze = [];
  $.ajax({
    type: 'GET',
    dataType: 'json',
    url: "{{ route('ordine_mp.lista_lunghezze') }}",
    data: {
      id_particolare: id_particolare
    },
    success: function(response) {
      $.each(response, function(index, element) {
        lista_lunghezze.push(element);
        option = {};
      });

      editor_detail.field('lunghezza').update( lista_lunghezze );
    },
    error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + XMLHttpRequest.responseText + "\n" + exception); },
    async: false
  });
}

The code works, the Select2 are rightly populated, but when I click to the cell with the select, the option selected is always blank, empty. So I have to reselect the option in the dropdown to save the value.

What's wrong?
Thanks!


Viewing all articles
Browse latest Browse all 82219

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>