I want to dynamically add new rows for each prescription I make, I am using select2 class in the select list but each time I add a row, the second row is disabled and unable to select new item.
<select name="medicine[]" class="form-control calcEvent medicine itemName select2" id="medicine" required>
<option>---Select Medicine ---</option>
<?php
$result = $this->db->get('db_items')->result();
foreach ($result as $medicine) {
?>
<option value="<?php echo $medicine->id; ?>"><?php echo $medicine->item_name; ?></option>
<?php }
?>
</select>
this is what happens when I select
I tried to use ajax to allow search in the text select field but I didn't work. this is my ajax code
var base_url = $('#base_url').val();
$('.itemName').select2({
placeholder: '--- Select Item ---',
allowClear: true,
ajax: {
url: base_url + 'prescription/searchmed',
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: data,
allowClear: true
};
},
cache: true
}
});
when adding new row, this is how I do
var add_button = $('.add_button');
var delete_button = $('.delete_button');
//var wrapper = $('.field_wrapper');
var x = 1;
$(add_button).click(function() {
if (x < max_field) {
x++;
//$(wrapper).append(html_fields);
// var clone = $(".table tr:last").clone().find('input').val('').end().insertAfter(".table tr:last");
var newRow = $(".table tr:last").clone(true).find(':input').val('').end();
$(".table").append(newRow);
}
});
I have tried several links here but couldn't get through this