Reply To: clone a row with dropdown – and new dropdown becomes un clickable

#10033584
Support
Keymaster

Hello Pelle,

My suggestion for you is use this new code for #addMore on click event:

$('#addMore').on('click', function () {          
    // TR ROW HTML
    var row_to_append = '<tr>' + 
        '<td><input type="text" name="id[]" class="form-control"></td>' + 
        '<td>' + 
           '<select name="contents[]" data-plugin-selectTwo class="form-control populate" style="width: 100%;">' + 
                '<option value="0">-- välj bedömning --</option>' + 
                '<option value="1">Felaktig</option>' + 
                '<option value="2">Kräver reparation</option>' + 
                '<option value="3">Ingen åtgärd</option>' + 
            '</select></td>' + 
        '<td><input type="text" name="Brist[]" class="form-control"></td>' + 
        '<td>' + 
            '<div class="input-group">' + 
                '<span class="input-group-btn">' + 
                    '<button onclick="javascript:void(0);" id="addMore" class="adding btn btn-light btn-pluss" type="button">+</button>' + 
                '</span>' + 
                '<span class="input-group-btn pl-1">' + 
                    '<button onclick="javascript:void(0);" class="remove btn btn-light btn-minuse" type="button">-</button>' + 
                '</span>' + 
            '</div>' + 
        '</td>' + 
    '</tr>';

    $("#tb").append( row_to_append );

    // Initialize the new select
	$("#tb tr:last-child").find( 'select' ).select2({
		theme: 'bootstrap'
	});
});

Regarding ID’s. My suggestion for you is don’t use ID’s (for example #addMore). Instead of it you can use class .add-more. You cant have duplicated elements with same ID’s, since ID is unique.

We hope this helps!

Kind Regards,

Rodrigo.


If you are satisfied with Porto Admin and our support, please leave your comment and rating on ThemeForest downloads page. That helps us a lot: https://themeforest.net/downloads