Skip to content

Commit bf7480d

Browse files
committed
Adding local storage support for vote form
1 parent a76cffd commit bf7480d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

app/views/papers/_vote_summary.html.erb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<div class="form-group">
1010
<div class="row">
1111
<div class="col">
12-
<%= f.text_area :comment, class: "form-control", placeholder: "Include a comment with your vote (required)" %>
12+
<%= f.text_area :comment, class: "form-control", placeholder: "Include a comment with your vote (required)",
13+
data: { paper_id: @paper.id }, id: "vote-comment" %>
1314
</div>
1415
</div>
1516
</div>
@@ -28,6 +29,31 @@
2829
</div>
2930
</div>
3031

32+
<script>
33+
document.addEventListener('DOMContentLoaded', function() {
34+
const commentField = document.getElementById('vote-comment');
35+
const paperId = commentField.dataset.paperId;
36+
const storageKey = `vote_comment_${paperId}`;
37+
38+
// Load saved comment if it exists
39+
const savedComment = localStorage.getItem(storageKey);
40+
if (savedComment) {
41+
commentField.value = savedComment;
42+
}
43+
44+
// Save comment on input
45+
commentField.addEventListener('input', function() {
46+
localStorage.setItem(storageKey, this.value);
47+
});
48+
49+
// Clear storage when form is submitted
50+
const form = commentField.closest('form');
51+
form.addEventListener('submit', function() {
52+
localStorage.removeItem(storageKey);
53+
});
54+
});
55+
</script>
56+
3157
<div class="form-group">
3258
<%= link_to "View vote summary &raquo;".html_safe, "#voteSummary", class: 'tooltips', title: 'View vote summary', data: { toggle: 'collapse'} %>
3359

0 commit comments

Comments
 (0)