Ask Your Question
4

How can I create dynamic menu options for a custom TinyMCE button?

asked 2021-07-16 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-24 19:00:00 +0000

qstack gravatar image

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:

  1. Register the custom button and its onclick event handler:
    editor.addButton('mycustombutton', {
        text: 'My Custom Button',
        onclick: function() {
            openMyPopup();
        }
    });
  1. Define the 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
        // ...
    }
  1. 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.

  2. 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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-07-16 11:00:00 +0000

Seen: 9 times

Last updated: Aug 24 '21