xapian #1
|
@ -8,6 +8,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function addForm(button) {
|
||||||
|
var formCount = parseInt(document.getElementById('id_form-TOTAL_FORMS').value);
|
||||||
|
var formCopy = $(document.querySelector('#id_form-0-name')).parent().parent().parent()[0].cloneNode(true);
|
||||||
|
// formCopy.style.display = 'block';
|
||||||
|
formCopy.innerHTML = formCopy.innerHTML.replace(/__prefix__/g, formCount);
|
||||||
|
document.getElementById('formset-container').appendChild(formCopy);
|
||||||
|
document.getElementById('id_form-TOTAL_FORMS').value = formCount + 1;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
{% load django_bootstrap5 %}
|
{% load django_bootstrap5 %}
|
||||||
<form role="form" method="post">
|
<form role="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -22,34 +33,33 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# bootstrap_form form #}
|
{{ form.management_form }}
|
||||||
<div class="form-actions-no-box">
|
<div class="container" id="formset-container">
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col"></div>
|
||||||
|
<div class="col-2 text-center">
|
||||||
|
<a href="javascript:void()" onclick="addForm(this);" type="button" class="btn btn-green-admin">
|
||||||
|
<i class="bi bi-plus"></i>
|
||||||
|
{% trans 'Add' %}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% for f in form %}
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col">
|
||||||
|
{% bootstrap_field f.name %}
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{% bootstrap_field f.value %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
||||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
<script>
|
|
||||||
function addForm(button) {
|
|
||||||
var formCount = parseInt(document.getElementById('id_form-TOTAL_FORMS').value);
|
|
||||||
var formCopy = document.querySelector('.dynamic-form').cloneNode(true);
|
|
||||||
formCopy.style.display = 'block';
|
|
||||||
formCopy.innerHTML = formCopy.innerHTML.replace(/__prefix__/g, formCount);
|
|
||||||
document.getElementById('formset-container').appendChild(formCopy);
|
|
||||||
document.getElementById('id_form-TOTAL_FORMS').value = formCount + 1;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<form method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div id="formset-container">
|
|
||||||
{% for f in form %}
|
|
||||||
<div class="dynamic-form" style="display: {% if forloop.first %}block{% else %}none{% endif %};">
|
|
||||||
{{ f.as_p }}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<button type="button" onclick="addForm(this);">Add</button>
|
|
||||||
<button type="submit">Submit</button>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -21,14 +21,21 @@ class NewDeviceView(DashboardView, FormView):
|
||||||
template_name = "new_device.html"
|
template_name = "new_device.html"
|
||||||
title = _("New Device")
|
title = _("New Device")
|
||||||
breadcrumb = "Device / New Device"
|
breadcrumb = "Device / New Device"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('device:add')
|
||||||
|
# success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||||
form_class = DeviceFormSet
|
form_class = DeviceFormSet
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.owner = self.request.user
|
# import pdb; pdb.set_trace()
|
||||||
|
# form.instance.owner = self.request.user
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def form_invalid(self, form):
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
|
response = super().form_invalid(form)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
# class AddToLotView(DashboardView, FormView):
|
# class AddToLotView(DashboardView, FormView):
|
||||||
# template_name = "list_lots.html"
|
# template_name = "list_lots.html"
|
||||||
|
|
Loading…
Reference in New Issue