[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,
- click any text and you see the icon and input field.
- type any text inside the input field
- blur the focus so that result function is triggered.
- 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)
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.
Issue #957
[Question] Add custom attributes (data-) to assets/images on Upload/Selection
Hi, I am trying my best to find the proper/best way to do this, but I need to attach two custom HTML5 data tags to an image once it is sele...
Issue #1650
[Question] How to remove a link from text(remove a link)
using built-in RTE and trying to add a rte custom button that when clicking, it removes current link. Could you provide me with the code pl...
Issue #1706
[Question]: How to get href from rte?
I have this rte toolbar where you can type and click 'save' and it's going to create a link for the selected text. but the problem is that...
Issue #572
rich text editor issue
How to add the icon of ordered List in rich text editor? Here is my code. rte.add('insertOrderedList', { icon: '',//how to add the icon of...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.