4

I have written own plugin which generates a simple link. The strange thing is that I can not editing "href" attribute. Other attributes can be edited.

This element does not work:

{
    type: 'text',
    id: 'url',
    label: 'URL',
    commit: function(element) {
        element.setAttribute('href', this.getValue());
    },
    setup: function(element) {
        this.setValue(element.getAttribute('href'));
    }
}

When I create a link, href attribute is written. When I editing a link "href" attribute is not changed. Strange!

When I change the code above and rewrite name of attribute for example to "href-s":

{
    type: 'text',
    id: 'url',
    label: 'URL',
    commit: function(element) {
        element.setAttribute('href-s', this.getValue());
    },
    setup: function(element) {
        this.setValue(element.getAttribute('href-s'));
    }
}

Creation and editing attribute works perfectly.

You do not know what's the problem?

Thank you.

1 Answer 1

2

For various internal reasons, CKEditor uses data-cke-saved-href attribute to duplicate href during runtime. So what in the output would look like

<p>I&#39;m a <a href="http://foo.com">plain&nbsp;link</a>.</p>

<p>I&#39;m a <a href="mailto:[email protected]?subject=Subject&amp;body=Body">mailto link</a>.</p>

is actually something different in editor DOM

<p>I'm a <a data-cke-saved-href="http://foo.com" href="http://foo.com">plain&nbsp;link</a>.</p>

<p>I'm a <a data-cke-saved-href="mailto:[email protected]?subject=Subject&amp;body=Body" href="mailto:[email protected]?subject=Subject&amp;body=Body">mailto link</a>.</p>

Update the data- attribute each time you change href and things should go right.

Sign up to request clarification or add additional context in comments.

1 Comment

Fighting the exact same problem today. Much obliged!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.