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

Empty img alt="" attribute automatically removed on entry save. #259

Closed
jlcharette opened this issue Aug 20, 2020 · 2 comments
Closed

Empty img alt="" attribute automatically removed on entry save. #259

jlcharette opened this issue Aug 20, 2020 · 2 comments
Labels

Comments

@jlcharette
Copy link

Description

Empty alt="" attributes on images get removed.

I found in https://github.com/craftcms/redactor/blob/v2/src/assets/field/src/js/RedactorOverrides.js
the following snippet:

    // remove image attributes
    var $wrapper = this.utils.buildWrapper(html);
    var imageattrs = ['alt', 'title', 'src', 'class', 'width', 'height', 'srcset', 'style'];
    $wrapper.find('img').each(function(node) {
        if (node.attributes.length > 0) {
            var attrs = node.attributes;
            for (var i = attrs.length - 1; i >= 0; i--) {
                if (attrs[i].name.search(/^data\-/) === -1 && imageattrs.indexOf(attrs[i].name) === -1) {
                    node.removeAttribute(attrs[i].name);
                }
            }
        }
    });

Which seems to be the cause of my issue.

Is there a way to override this so the empty alt="" attr is allowed? I absolutely need to follow this guideline:
https://www.w3.org/WAI/WCAG21/Techniques/html/H67.html

Steps to reproduce

  1. Add an image
  2. Insert alt="" via the code view
  3. Save entry
  4. The alt tag has been removed

Additional info

  • Craft version: 3.4.30
  • PHP version: 7.4.8
  • Database driver & version: MySQL 8.0.21
  • Plugins & versions: Redactor 2.6.1
@andris-sevcenko
Copy link
Contributor

Just pushed a fix for this. I'll see if I can get a Redactor release out next Tuesday!

@bryanluu
Copy link

bryanluu commented Feb 22, 2023

How would I go about removing the alt="" attribute entirely? I'm hoping to make Assets uploaded directly into a Redactor field use the Asset's alt-text. Currently when I upload the asset into a Redactor field, it uses the "Title" field from Redactor's uploader to act as the asset's alt-text.
Screenshot from 2023-02-21 16-03-46
Screenshot from 2023-02-21 16-06-09


(Update)
I was able to find an answer on the Craft Stack exchange:

It seems like that capability isn't implemented in Craft yet, to have Redactor fields use the asset's alt-text. Perhaps an issue/feature suggestion is to be able to configure the Upload fields in a Redactor field? So changing the "Title" text to be "Title (used as alternative text)" or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants