aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-06 00:10:44 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-06 01:02:08 +0200
commitcffe6351a9f8e2777b6d4c078c89bd8f215de603 (patch)
tree132b7b9be16bd53d4baa017c1eabecfaa34e5c98
parent08d3d9aab4845b863d868ca0e43e21c9f7f54203 (diff)
Fixed edit function not working because js bs
Because for loop would declare a global variable, the closures would use the el of previous scope.
-rw-r--r--t_idea/edit.html2
-rw-r--r--t_idea/index.html19
2 files changed, 10 insertions, 11 deletions
diff --git a/t_idea/edit.html b/t_idea/edit.html
index 8a7885c..725a111 100644
--- a/t_idea/edit.html
+++ b/t_idea/edit.html
@@ -33,7 +33,7 @@ input[name="title"] {
<div class="idea">
<form action="/idea/edit/" method="post">
<input name="title" type="text" value="{{.Title}}"><br>
- <textarea name="text" rows=4 required>{{.Text}}</textarea>
+ <textarea name="text" rows=6 required>{{.Text}}</textarea>
<p class="creation">by <span class="author">{{.Author}}</span> on <span class="date">{{.CreatedAt}}</span></p>
<input type="submit" value="confirm">
</form>
diff --git a/t_idea/index.html b/t_idea/index.html
index f845628..97b68dd 100644
--- a/t_idea/index.html
+++ b/t_idea/index.html
@@ -40,24 +40,23 @@
<p><i>No ideas here... Be the first one to think!</i></p>
{{ end }}
</ul>
- <!--template-->
</body>
<script>
- let dels = document.querySelectorAll("form[action=\"/idea/delete/\"]")
- for (el of dels) {
+ let dels = document.querySelectorAll("form[action=\"/idea/delete/\"]");
+ for (let el of dels) {
el.addEventListener("submit", function(e) {
- e.preventDefault()
+ e.preventDefault();
if (confirm("are you sure?") === true) {
- this.submit()
+ this.submit();
}
})
}
- let eels = document.querySelectorAll("button.edit")
- for (el of eels) {
- el.onclick = function(e) {
- location.href = "/idea/edit?t=" + el.getAttribute("data-title")
+ let eels = document.querySelectorAll("button.edit");
+ for (let el of eels) {
+ el.onclick = function() {
+ let title = el.getAttribute("data-title");
+ location.href = "/idea/edit?t=" + title;
}
}
-
</script>
</html>