I'm using Django-dynamic-formset to create template that adds formset when I click add button
On my formset there are two fields, one is CharField with choice_option and the other is CharField
When I click add button it adds formset properly and all my second field ( CharField with no choice_option) works well
However on my first field(CharField with choice_option), only the first select box works, and when I click the another select box below, the first select box is selected This is what happens when I click 2nd or below select box How can I make every select box work properly?
my code is like this which I followed https://github.com/elo80ka/django-dynamic-formset/blob/master/docs/usage.rst
Thanks in advance
<form>
<table id="id_orders_table" border="0" cellpadding="0" cellspacing="0">
<tbody>
{% for inventory_form in inventory_formset %}
<tr>
<td>
{% if inventory_form.instance.pk %}{{ inventory_form.DELETE }}{% endif %} {{ inventory_form.inventory_type }}
</td>
<td>{{ inventory_form.inventory_description }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ inventory_formset.management_form }}
<input type="submit" value="submit" />
</form>
<script src="{% static 'js/jquery.formset.js'%}"></script>
<script type="text/javascript">
$(function() {
$('#id_orders_table').formset({
prefix: '{{ inventory_formset.prefix }}'
});
})
</script>
if you are using materilizecss it will work. Or any cssframework. just find the way to initialize the select box. And create a function to initialize the select and call it on everytime when you add new row in formset. it can done by passing that function to fomset.which i mentioned below
function initialize_select(){
$('select').material_select();
}
$(function() {
$('#id_orders_table').formset({
'prefix': '{{ inventory_formset.prefix }}',
'added':initialize_select
});
})