Issue #1669Opened December 18, 2018by SeongwoonHong0 reactions

[Question] Custom link modal doesn't update the current text but add another text with link

Question

Hello Artur,

I'm trying to have a custom modal when clicked link button in RTE. but it doesn't convert selected text to link but what it does is it adds another text with link.

      this.editor.RichTextEditor.add('custom-link', {
        icon: '<img src="assets/images/link.png" />',
        attributes: {title: 'Link', class: 'gjs-rte-action'},
        result: rte => {
          // define what's going inside modal
          const customLinkContainer = document.createElement('div');
          const btnLink = document.createElement('button');
          const linkInputEl = document.createElement('input');
          linkInputEl.setAttribute('id', 'custom-link-input');
          linkInputEl.value = `<a class="link" href="asdf">${rte.selection()}</a>`
          btnLink.innerHTML = 'aa';
          btnLink.onclick = () => {
            const inputEl = document.getElementById('custom-link-input');
            const selectedEl = this.rte.selection();
            rte.insertHTML(`<a class="link" href="${inputEl.value}">${rte.selection()}</a>`);
            modal.close();
          };
          customLinkContainer.appendChild(linkInputEl);
          customLinkContainer.appendChild(btnLink);

         // configure modal
          modal.setTitle(t('Link'));
          modal.setContent(customLinkContainer);
          modal.open();
        }
      });

Thank you..

Answers (3)

SeongwoonHongDecember 18, 20180 reactions

I'd like to add one more, inside onclick handler for btnLink, <a class="link" href="${inputEl.value}">${rte.selection()}</a> returns <a class="link" href="..."></a> the inner text is empty.. i have no idea how to approach this

lock[bot]December 20, 20190 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.