To create dynamic menu options for a custom TinyMCE button, you can use the onclick
event of the button to open a modal dialog or a popup and populate it with the dynamic options.
Here's an example of how to do it:
onclick
event handler: editor.addButton('mycustombutton', {
text: 'My Custom Button',
onclick: function() {
openMyPopup();
}
});
openMyPopup()
function that will open the popup and populate it with dynamic menu options: function openMyPopup() {
// 1. Create the popup
// 2. AJAX call to retrieve the dynamic menu options
// 3. Populate the popup with the menu options
// 4. Add event handlers to the menu options
// Example:
var popup = editor.windowManager.open({
title: 'My Custom Popup',
body: [
{
type: 'select',
name: 'myselect',
label: 'Select an option',
options: [] // Empty options, to be populated dynamically
}
],
onsubmit: function(e) {
// Handle the selected option
}
});
// AJAX call to retrieve the dynamic menu options
// ...
// Populate the select input with the options
// ...
// Add event handlers to the select input
// ...
}
In the openMyPopup()
function, you can use an AJAX call to retrieve the dynamic menu options, and then populate the popup with those options. You can also add event handlers to those options to handle the selected option.
Finally, in the onsubmit
event handler of the popup, you can handle the selected option and perform the desired action.
Note: Depending on your specific use case, you may need to adjust this example to fit your needs.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-07-16 11:00:00 +0000
Seen: 9 times
Last updated: Aug 24 '21
In Angular, how can a mat cross button be aligned to the right-most position within a div?
How can I detect the fullscreen button click event of an HTML5 video?
What is the method for modifying the button color in the antd Modal?
How can I create an HTML button that sends data to a different URL?
How can we use the Pywinauto library to automate the control of Proton VPN?
How can a button be utilized to display and hide the matplotlib live graph?
How can I activate a button using Angular Material?
Is it impossible to modify the color of button text on Android?
How can key and value be saved in admin setting using Opencart 3?