Trix: Make caption for previewable attachments optional

Created on 8 Nov 2015  路  9Comments  路  Source: basecamp/trix

Currently, previewable attachments have always a caption. If user does not specify one, it is set to filename and size. Could there be a way to make it so that there is just an empty prompt for a caption and if a user does not enter any then no caption is made. So the prompt could be similar to how it is currently when default caption gets focused.

enhancement

Most helpful comment

Please make it optional. I don't want any caption at all.

All 9 comments

Exactly. Users do not care about the file size and file names are even more misleading. Asking user to enter something after attaching every picture is quite cumbersome. It would be awesome if there is an empty value is allowed for caption.

I'm not sure if the caption currently gets used for the image's alt text. If it does, prompting for a value here is meaningful. The file name/size info is a confusing way to prompt tho.

Please make it optional. I don't want any caption at all.

Does anyone know a workaround?
It would be more than sufficient to cancel the event after fileupload that inserts the picture/file into the textarea. Currently it always adds it (or haven't found the solution in the docs).

Shouldn't this be now much easier once #197 has landed? Now this could be a hook which would be given file/filename and allow you to produce default caption. If you override the hook and make it so that it return empty string, then we get to the state of #197, where user can decide to enter a caption or not.

An easy way to disable this is to do it just with CSS:

figcaption.caption {
    display: none;
}

@alejorivera: I do not think so. Because here the idea is that caption can still be filled, but if it is empty, it should stay empty/hidden. Not to simply hide all captions.

If you're using Action Text (introduced in Rails 6), when you run the installer rails action_text:install, it will generate app/views/active_storage/blobs/_blob.html.erb, where you can configure the HTML rendering of your attachments :)

For instance if you only want to display a caption when the user added one, you can do:

<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
  <% if blob.representable? %>
    <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
  <% end %>

  <% if caption = blob.try(:caption) %>
    <figcaption class="attachment__caption">
      <%= caption %>
    </figcaption>
  <% end %>
</figure>

@spone - this only works if you're not serializing it directly into a text field like the default for trix is, though.

This is still a big deal and should be addressed, having the filename & size as a default caption is idiotic; the default should be no caption.

FYI the answer is in the download's example index.html:

Trix.config.attachments.preview.caption.name = false; Trix.config.attachments.preview.caption.size = false;

But OMG that should be the default. And there should be a document somewhere showing the Trix.config settings so we can find them without wandering through the (smaller than ckeditor but still pretty complex) code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javan picture javan  路  4Comments

souporserious picture souporserious  路  4Comments

lcsqlpete picture lcsqlpete  路  3Comments

benzkji picture benzkji  路  3Comments

andreimoment picture andreimoment  路  3Comments