2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-14 15:41:10 +00:00

Modal form is working for 'create new category'

- Had to set form.helper.form_tag to False (so we could control form tags manually)
- Created a 'json' model view
This commit is contained in:
Oliver
2018-04-25 12:46:58 +10:00
parent 9004086632
commit 8bc4050d05
5 changed files with 84 additions and 24 deletions

View File

@@ -38,21 +38,42 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$(document).ready(function () {
$(".js-create-cat").click(function () {
$.ajax({
url: '/part/category/new/',
type: 'get',
//dataType: 'json',
dataType: 'json',
beforeSend: function () {
$("#modal-cat").modal("show");
},
success: function (data) {
$("#modal-cat .modal-content").html(data);
//alert(data);
$("#modal-cat .modal-content").html(data.html_form);
}
});
});
$("#modal-cat").on("submit", ".js-modal-form", function () {
var form = $(this);
$.ajax({
url: form.attr('action'),
data: form.serialize(),
type: form.attr('method'),
dataType: 'json',
success: function (data) {
if (data.form_valid) {
alert("Success!");
}
else {
$("#modal-cat .modal-content").html(data.html_form);
}
}
});
return false;
});
});
</script>