Answer the question
In order to leave comments, you need to log in
How to implement the creation of a new object in the popup window with value initialization in the form?
The question is more about JavaScript.
Using the tutorial , I implement the ability to add new entities (ForeignKey and ManytoMany relationships) in the popup window. The tutorial uses one add button, but I'm trying with two.
Added the following code to the html form
{form.field1}
<a class="text-success" href="/project/create" id="add_project" onclick="return showAddPopup(this);"><i class="fas fa-plus fa-lg"></i></a>
{{ form.field2 }}
<a class="text-success" href="/technology/create" id="add_technology" onclick="return showAddPopup(this);"><i class="fas fa-plus fa-lg"></i></a>
<script type="text/javascript">
function showAddPopup(triggeringLink) {
var name = triggeringLink.id.replace(/^add_/, '');
href = triggeringLink.href;
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
return false;
}
function closePopup(win, newID, newRepr, id) {
$(id).append('<option value=' + newID + ' selected >' + newRepr + '</option>')
win.close();
}
</script>
Answer the question
In order to leave comments, you need to log in
So you have a pop-up for the project and for the technology are no different from each other. It is necessary either to use different callbacks or pass additional arguments in order to distinguish which of the popups has closed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question