I am trying to add a row to a table that includes a "select2" (plugin) field. Although I get the new row the new select2 select field doesn't work. Any idea why?
p.s.: The html is in Greek, this is why I am not pasting it as well, to avoid confusion. My guess is that its a jquery issue, but anyway if you need the html let me know.
var rowtemplate = $("tr#1").html();
function createRow(num){
var ns = "s" + num + "id_";
var numAdd = num + 1;
var autoGen = numAdd + 1;
var psomi = rowtemplate.replace("_1", "_"+num);
$("div.select2-container").remove(); // Remove all select2 elements
return '<tr id="'+ num +'" class="troption">' + psomi + '</tr>';
}
$('a[data-role="addrow"]').click(function(event) {
event.preventDefault();
var lastTr = $('tr.troption:last'),
lastTrid = parseInt(lastTr.attr("id")),
newid = lastTrid + 1;
newRowHtml = createRow(newid);
$('tr#'+lastTrid).after(newRowHtml);
// Recreate the select2 divs
$(".select2").select2({
allowClear: true
});
});
Firebug error = uncaught exception: query function not defined for Select2 s2id_autogen3