All threads / Commontator with Trix

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Commontator with Trix

Nelson Casanova asked in Gems / Libraries

Good day robots,

I'm trying to implement the Trix editor as the default editor for Commontator's comments.

The default Commontator view is defined as follows in app\views\commontator\comments\_form.html.erb:

<%= form_for([commontator, thread, comment],
             remote: !no_remote) do |f| %>
<div class="comment_form_field">
    <%= f.text_area :body, rows: '7' %>
    <%= javascript_tag('Commontator.initMentions()') if Commontator.mentions_enabled %>
</div>
<% end %>

So I get that I need to replace that text_area for the Trix default tag: <trix-editor input="???"></trix-editor> not sure what to put into the input parameter.

The generated HTML for the above form_for is as follows;

<form class="new_comment" id="new_comment" action="/commontator/threads/1/comments" accept-charset="UTF-8" data-remote="true" method="post">

<div class="comment_form_field">
    <div class="field_with_errors">
        <textarea rows="7" name="comment[body]" id="comment_body" spellcheck="false"></textarea>
    </div>
</div>

<div class="comment_form_actions">
    <input type="submit" name="commit" value="Post Comment" data-disable-with="Post Comment">
    <input type="submit" name="cancel" value="Cancel" data-disable-with="Cancel">
</div>

</form>

Any ideas? cheers!

I should feel ashamed of myself but I'm gonna go ahead and confess that I should have tried a bit harder.

I changed the text_area to hidden_field and added <trix-editor input="comment_body"></trix-editor> commentbody being the same id as the now hidden field.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.