Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofocus of reply textarea does not work when replying to a comment #181

Open
dssjoblom opened this issue Nov 3, 2020 · 0 comments
Open

Comments

@dssjoblom
Copy link

The autofocusing code does not work when replying to a comment, it only works when creating a new comment. The code in _new.js.erb is:

<%
  id = @comment.parent.nil? ? "commontator-thread-#{@commontator_thread.id}-new-comment" :
                              "commontator-comment-#{@comment.parent.id}-reply"
%>

$('#<%= id %>-body').focus();

And in _form.html.erb, the id is set as follows:

      form.text_area :body, rows: '7', id: new_record ?
        comment.parent.nil? ? "commontator-thread-#{@commontator_thread.id}-new-comment-body" :
                              "commontator-comment-#{comment.parent.id}-reply" :
        "commontator-comment-#{comment.id}-edit-body"

There are two problems: 1. if comment.parent is not nil, the id will not end in -body, hence it won't get focus 2. without the -body suffix, the id is actually a duplicate of another id, breaking e.g. id selectors.

My quick fix is to change _form.html.erb so that it reads:

      form.text_area :body, rows: '7', id: new_record ?
        comment.parent.nil? ? "commontator-thread-#{@commontator_thread.id}-new-comment-body" :
                              "commontator-comment-#{comment.parent.id}-reply-body" :
        "commontator-comment-#{comment.id}-edit-body"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant