I have a signup form that works great. One feature of it is users can press "Add more +" and have more identical "instrument" and "level" select fields created. The model only saves the first "instrument" and "level" field and not the further ones created from the javascript function. How can I adjust my model to create further fields when the javascript function is called? I appreciate any help I get.
models.py
class User(AbstractBaseUser):
instrument = models.CharField(max_length=255, choices=instrument_list)
level = models.CharField(max_length=255, choices=level_list)
HTML
<div>
<div class="items">
<div id="ins">
<div>
{{ form.instrument }}
</div>
<div>
{{ form.level }}
</div>
</div>
</div>
<div id="add_more">
<button type="button" class="no_link" onclick="add_instrument()">Add more +</button>
</div>
</div>
Javascript
var i = 0;
var original = document.getElementById('ins');
function add_instrument() {
var clone = original.cloneNode(true);
clone.id = "ins" + ++i;
original.parentNode.appendChild(clone);
}