Issue #1702Opened January 2, 2019by SeongwoonHong0 reactions

[Question]How to get rte selection inside the result function

Question

rte.add('custom-link', {
          icon: '<div><img src="assets/images/link.png" /><input name="link" id="custom-link-input" value="" /></div>',
          attributes: {title: 'Link', class: 'gjs-rte-action'},
          event: 'change',
          result: (rte) => {
            console.log(`<a href="#">${rte.selection()}</a>`)
          },
          update: (rte, action) => {
            // ...
          }
        });

I'm basically trying to put an input fieldinside the RTE so that users can make link more easily. console.log(<a href="#">${rte.selection()}</a>) inside the result function is returning an empty anchor tag like this <a href="#></a>. I've tried everything.. even store the rte.selection() value to the global variable inside the update function (as it seems like update function has the correct value) and reuse inside the result function but none of them worked. so basically,

  1. click any text and you see the icon and input field.
  2. type any text inside the input field
  3. blur the focus so that result function is triggered.
  4. see the console and it says <a href="#></a> for now, href is always # cuz i will add value later on. but the problem is rte.selection() is empty.. your help would be really appreciated. thank you

Answers (1)

lock[bot]January 4, 20200 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.