I'm using this module and LinkIt 8.x-5.x (last dev). If I insert link https://www.drupal.org/ I get this:
<a href="https://www.drupal.org/" id="" rel="" target="" title="">Drupal</a>

How I can hide empty attributes?

CommentFileSizeAuthor
#5 hide_empty_attributes-2766191-5.patch2.96 KBanon

Comments

sashken2 created an issue. See original summary.

sashken2’s picture

Issue summary: View changes
duaelfr’s picture

Could you try without Linkit to see if it's related or if it's an issue of Editor Advanced Link ?

I did something special to be able to remove the target attribute when unchecked so I suppose there is a problem within Linkit but I'd like to be sure.

sashken2’s picture

Uninstall Linkit. Clear all cache. Try insert link and get this in editor:
<p><a href="https://www.drupal.org/" id="" rel="" target="" title="">Test</a></p>
This only first time link create with empty all attributes.

If I click Edit this link and (do nothing) click Save, I get this:
<p><a href="https://www.drupal.org/">Test</a></p>

anon’s picture

Status: Active » Needs work
StatusFileSize
new2.96 KB

This is not as simple as it looks. I had the same problem with in the Linkit module.

When editing a link, returning empty attributes will remove the attribute from the link, but when adding, there is no check in the savecallback javascript to remove empty attributes.

So we need to handle add and edit in different ways.

The first problem is to know the state in the form (add or edit). I think the patch shows the correct way, but I am not sure.
Then, in the submit callback, we need to use that state, and set unset the values if we are in an add state.

  • DuaelFr committed fef08c8 on 8.x-1.x
    Issue #2766191 by anon, sashken2, DuaelFr: Hide empty attributes
    
duaelfr’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Status: Needs work » Fixed

I think I finally found something working in every cases.
Thanks for your help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.