Skip to content

Commit d0be299

Browse files
authored
Merge pull request #1711 from codidact/0valt/1710/comment_reply
Fix for identifier uniqueness for comment-related controls
2 parents 67321e8 + 86f77b0 commit d0be299

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

app/assets/javascripts/comments.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ $(() => {
313313
ev.preventDefault();
314314
const $tgt = $(ev.target);
315315
const postId = $tgt.attr('data-post');
316-
const $reply = $(`#reply-to-thread-form-${postId}`);
316+
const threadId = $tgt.attr('data-thread');
317+
const $reply = $(`#reply-to-thread-form-${postId}-${threadId}`);
317318

318319
if ($reply.is(':hidden')) {
319320
$reply.show();

app/views/comments/_new_thread_modal.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
required: true,
3232
data: { post: post.id,
3333
thread: '-1',
34-
character_count: ".js-character-count-#{post.id}" } %>
35-
<%= render 'shared/char_count', type: post.id, min: min_chars, max: max_chars %>
34+
character_count: ".js-character-count-new-thread-#{post.id}" } %>
35+
<%= render 'shared/char_count', type: "new-thread-#{post.id}", min: min_chars, max: max_chars %>
3636

3737
<%= label_tag :title, 'Comment thread title (optional)', class: 'form-element' %>
3838
<span class="form-caption">

app/views/comments/_reply_to_thread.html.erb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
%>
1111

1212
<%
13+
# TODO: make configurable
14+
min_chars = 15
15+
max_chars = 1000
16+
1317
can_comment = user.can_reply_to?(thread)
1418
is_rate_limited, rate_limit_message = comment_rate_limited?(user, post, create_audit_log: false)
1519
text ||= defined?(text) && text.present? ? text : t('comments.labels.reply_to_thread')
@@ -28,7 +32,7 @@
2832

2933
<div class="reply-to-thread-wrapper">
3034
<%= link_to 'javascript:void(0)', class: 'button is-outlined is-small js-reply-to-thread-link',
31-
data: { post: post.id },
35+
data: { post: post.id, thread: thread.id },
3236
disabled: !can_comment,
3337
role: 'button',
3438
title: is_exempt ? '' : title do %>
@@ -40,16 +44,20 @@
4044
</div>
4145

4246
<% if can_comment %>
43-
<%= form_tag create_comment_path(thread.id), class: 'reply-to-thread-form', id: "reply-to-thread-form-#{post.id}" do %>
47+
<%= form_tag create_comment_path(thread.id), class: 'reply-to-thread-form',
48+
id: "reply-to-thread-form-#{post.id}-#{thread.id}" do %>
4449
<%= hidden_field_tag :post_id, post.id %>
4550
<%= hidden_field_tag :inline, inline %>
4651
<%= label_tag :content, 'Your message', class: 'form-element' %>
4752
<%= text_area_tag :content, '',
4853
class: 'form-element js-comment-field',
54+
minlength: min_chars,
55+
maxlength: max_chars,
56+
required: true,
4957
data: { thread: thread.id,
5058
post: thread.post_id,
51-
character_count: ".js-character-count-#{post.id}" } %>
52-
<%= render 'shared/char_count', type: post.id, min: 15, max: 1000 %>
59+
character_count: ".js-character-count-thread-reply-#{post.id}-#{thread.id}" } %>
60+
<%= render 'shared/char_count', type: "thread-reply-#{post.id}-#{thread.id}", min: min_chars, max: max_chars %>
5361
<%= submit_tag 'Add reply', class: 'button is-muted is-filled', disabled:true %>
5462
<% end %>
5563
<% end %>

0 commit comments

Comments
 (0)