0

I have created a custom dropdown for trumbowyg following this guide, but am stuck on how to really insert a text when a dropdown button is clicked.

$('.editor').trumbowyg({
    btnsDef: {
        tagSelect: {
            fn: () => {
                // how to insert test to cursor's position?
            },
            text: 'Name Tag',
            hasIcon: false
        },
        detailsType: {
            dropdown: [
                'tagSelect',
            ],
            title: 'Client Tag',
            hasIcon: false
        }
    },
    btns: [
        ['detailsType']
    ]
})
shaNnex
  • 1,043
  • 2
  • 19
  • 34

1 Answers1

0

I did this by using the plugin "mention".

Using that plugin it's as simple as this:

$('#editorid').trumbowyg({
    plugins: {
                mention: {
                    source: [
                        { mergetag: '[RECIPIENT_NAME]', name: 'Full name of the recipient' },
                        { mergetag: '[RECIPIENT_NAME_FIRST]', name: 'First name of the recipient' },
                        { mergetag: '[SENDER_NAME]', name: 'Name of sender' },  
                        { mergetag: '[SENDER_MAIL]', name: 'Sender email' },  
                        { mergetag: '[SIGNATURE]', name: 'Senders mailsignature' }
                    ],
                    formatDropdownItem: function (item) {
                        return item.name + ' ' + item.mergetag;
                    },
                    formatResult: function (item) {
                        return item.mergetag;
                    }
                }
            }
});

More info here: https://alex-d.github.io/Trumbowyg/demos/plugins/mention.html

Muleskinner
  • 14,150
  • 19
  • 58
  • 79