Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create js_add_form.html #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/js_add_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% extends "dashboard/index.html" %}
{% block content_dashboard %}
<form method="post" action="{% url 'create_multi_genere_book'%}">
{% csrf_token %}
<div class="row">
<div class="col-lg-12">
<div id="inputFormRow">
<div class="input-group mb-3">
<div class="col-sm-4">
<select class="form-control" name="genere[]" required>
<option selected value="">------</option>
{% for genere in generes %}
<option value={{genere.id}}>{{genere.name}}</option>
{% endfor %}
</select>
</div>
<div class="col-sm-4">
<input type="number" min="1" name="book_number[]"
class="form-control m-input" placeholder="Enter number"
autocomplete="off" required>
</div>
<div class="col-sm-2"></div>
</div>
</div>

<div id="newRow"></div>
<button id="addRow" type="button" class="btn btn-primary">Add Row</button>
<button id="submit-" type="submit" class="btn btn-info">Submit</button>
</div>
</div>
</form>
{% endblock %}

{% block extend_js %}
<script type="text/javascript">
// add row
$("#addRow").click(function () {
var html = '';
html = `
<div id="inputFormRow">
<div class="input-group mb-3">
<div class="col-sm-4">
<select class="form-control" name="genere[]" required>
<option value="" selected>------</option>
{% for genere in generes %}
<option value={{genere.id}}>{{genere.name}}</option>
{% endfor %}
</select>
</div>
<div class="col-sm-4">
<input type="number" min="1" name="book_number[]"
class="form-control m-input" placeholder="Enter number"
autocomplete="off" required>
</div>
<div class="col-sm-2">
<button id="removeRow" type="button" class="btn btn-danger">Remove</button>
</div>
</div>
</div>
`

$('#newRow').append(html);
});

// remove row
$(document).on('click', '#removeRow', function () {
$(this).closest('#inputFormRow').remove();
});
</script>
{% endblock %}