Hi Team,
I am trying to create a custom button on RTE toolbar but facing issue.
For this, I have added a custom client lib for author instance and added my logic there, I see, my client lib load correctly and function are also trigger as expected but I am not able to create/append my custom button in rte toolbar.
I found few old blogs which one of them for length validation, I customize that and write my logic there.
https://sourcedcode.com/blog/aem/touch-ui/aem-richtext-max-characters-length-validation
Sample code:
(function ($, $document) {
"use strict";
$(document).on("dialog-ready", function () {
var mycustombutton = `<button is="coral-button" variant="quietaction" class="rte-toolbar-item disabled _coral-ActionButton _coral-ActionButton--quiet" type="button" title="Unlink" icon="linkOff" data-action="links#unlink" tabindex="-1" size="M" aria-checked="false" role="checkbox">
<coral-icon size="S" class="_coral-Icon--sizeS _coral-Icon" role="mycustomrole" icon="useAnyicone"></coral-icon>
<coral-button-label class="_coral-ActionButton-label">custom button</coral-button-label></button>`
//find all the RTE and append the custom button
$('.rich-custom-dataBids').each(function () {
//First I tried to append a button by appendButton() method
// like: author.EditorFrame.editableToolbar.appendButton(editable, name, action);
// but I am not sure how I can pass a button into appendButton() method since it have 2 parmamete
// var customButton = {
// icon: 'mycustomrole',
// text: 'custom button',
// handler: function (editable, param, target) {
//
// },
// condition: function (editable) {
// //show this button only for component type if needed
// return editable
// },
// isNonMulti: true
// };
// $document.on('cq-layer-activated', function (ev) {
// if (ev.layer === 'Edit') {
// author.EditorFrame.editableToolbar.registerAction('custom button', customButton);
// }
// });
//seems this is not right way to do this
$(this).parent().find(".rte-toolbar")[0].append(mycustombutton);
});
//custom click event for custom opration
$('.rich-custom-dataBids').click(function (e) {
var $target = $(e.target);
// do something
});
});
})($, $(document));
using append(mycustombutton) I can able to add my button but I want to register or append it in correct way. Can some suggest on this?
Thanks
Abhishek
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @Abhishekty
AEMaaCS RTE compatible version is - aem-rte-plugins-1.5.zip
Hi @Abhishekty
You can check examples for creating/adding custom plugins in RTE https://aemlab.blogspot.com/2019/07/aem-rte-custom-plugins-1.html
Hi @arunpatidar,
Thanks for the suggestion, nice informative article, I'm trying to use it with AEMaaCS and it's not working. Can you please explain how we are adding/registering the custom button to the toolbar?
I just want to add a custom button on the above toolbar, my other functionalities are working fine. If you can explain in your code.
Thanks
Abhishek
Hi @Abhishekty
AEMaaCS RTE compatible version is - aem-rte-plugins-1.5.zip
Hi @Abhishekty
Here's my take on tackling this challenge:
1. Leveraging the rte Extension Point:
The preferred way to customize the RTE toolbar in AEM 6.5+ is through the rte extension point. This provides a dedicated mechanism for extending the RTE functionality. Here's how you can use it:
2. Inspecting your Existing Approach:
Based on the provided link, it seems you're relying on a custom client-side library and logic embedded within it. While this might work to some extent, it's considered less robust and lacks the benefits of leveraging the rte extension point:
3. Additional Tips:
Thanks
@Abhishekty Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies