Skip to content

Commit c4f5068

Browse files
Chimpkillerrhoit
authored andcommitted
proposals - comment-dialog.djhtml form submission with fetch api
1 parent a470b48 commit c4f5068

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

srv/templates/proposals/comment-dialog.djhtml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
</style>
77

88
<header style="padding:1rem 0; border-bottom: solid lightgray 1px; font-weight:600; font-size:110%;">
9-
<span class="dialog-title"></span>
9+
<span class="dialog-title">Drop your comment</span>
1010
</header>
1111

12-
<form method="dialog" class="dialog-form" style="padding-top:1.5rem">
12+
<form id="form" method="dialog" style="padding-top:1.5rem">
1313
<fieldset>
14-
<textarea></textarea>
14+
<textarea name="comment"></textarea>
1515
</fieldset>
1616
<button class="button">Submit</button>
17-
<div style="display:flex; justify-content:flex-end;"></div>
1817
</form>
1918

2019
<script>
@@ -32,5 +31,21 @@
3231
dialog.close()
3332
}
3433
})
34+
35+
document.getElementById('form').addEventListener('submit', function(event){
36+
event.preventDefault()
37+
const formdata = new FormData(event.target)
38+
39+
fetch('/reviews/add/{{proposal_pk}}', {
40+
method : 'POST',
41+
body : formdata,
42+
}).then(function (response){
43+
return response.text()
44+
}).then(function (textData){
45+
location.reload()
46+
}).catch(function (error){
47+
alert(error.message)
48+
})
49+
})
3550
</script>
3651
</dialog>

0 commit comments

Comments
 (0)