question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting html from editor does not work | trumbowyg is not a function

See original GitHub issue

Description

System information

OS: Windows 10 Browser: Opera Trumbowyg Version: v2.18.0

Expected behavior

I want to get html from editor and POST the result with an AJAX request if onClick event occurs.

The following code is defined to achieve this goal:

$(document).ready(function(){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': "{{ csrf_token() }}"
                }
            });

            $(document).on('click', '#save', function(){
                var htmlDoc = $('#editor').trumbowyg('html');
                $.ajax({
                    method: 'POST',
                    url: '/user/documents/{{$document->id}}/edit',
                    data: {
                        created_doc : htmlDoc,
                    },
                    success: function(response){ 
                        console.log(response);
                    },
                    error: function(jqXHR, textStatus, errorThrown){ 
                        console.log(JSON.stringify(jqXHR));
                        console.log("AJAX error: " + textStatus + + ' : ' + errorThrown);
                    }
                });
            });
        });

Error which occurs

When firing the event up the following error is shown in the console:

Uncaught TypeError: $(...).trumbowyg is not a function
    at HTMLAnchorElement.<anonymous> (edit:345)
    at HTMLDocument.dispatch (jquery.min.js:3)
    at HTMLDocument.q.handle (jquery.min.js:3)

How to reproduce?

Unfortunately it is not possible to provide a live-link to this project, but you should be able to represent the behavior with the provided code above.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rwolfdevcommented, Jun 25, 2019

Solution was adding $.noConflict(); to the first line after the definition of the function inside document ready.

0reactions
rwolfdevcommented, Jun 25, 2019

I initialized the editor outside of the document ready function, cause inside of the function I am getting the error that trumbowyg is not a function.

An editor element is defined, cause it shows me trumbowyg, just the event do not work!

I´ve defined it in the way you explained above, here is my code-snippet (which does not work!!!)

 $(document).ready(function(){
            $('#editor').trumbowyg({
                lang: 'de',
                autogrow: true,
                changeActiveDropdownIcon: true,
                disabled: false,
                btns: [
                    ['template'],
                    ['formatting'],
                    ['fontfamily'],
                    ['fontsize'],
                    ['strong', 'em', 'del'],
                    ['table'],
                    ['superscript', 'subscript'],
                    ['base64'],
                    ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
                    ['unorderedList', 'orderedList'],
                    ['undo', 'redo'], // Only supported in Blink browsers
                    ['removeformat'],
                    ['viewHTML'],
                    ['fullscreen'],
                ],
                plugins: {
                    resizimg: {
                        minSize: 64,
                        step: 16,
                    },
                    table:{
                        rows: 10,
                        columns: 10
                    },
                    fontfamily: {
                        fontList: [
                            {name: 'Arial', family: 'Arial, Helvetica, sans-serif'},
                            {name: 'Open Sans', family: '\'Open Sans\', sans-serif'}
                        ]
                    },
                    templates: [
                            {
                                name: 'blabla',
                                html: 'test1'
                            },
                            {
                                name: 'Template 2',
                                html: 'Test2',
                            }
                    ]
                }
            });

            $('#editor').trumbowyg('html', '{!! $document->delivered_doc !!}');

            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': "{{ csrf_token() }}"
                }
            });

            $(document).on('click', '#save', function(){
                var htmlDoc = $('#editor').trumbowyg('html');
                $.ajax({
                    method: 'POST',
                    url: '/user/documents/{{$document->id}}/edit',
                    data: {
                        created_doc : htmlDoc,
                    },
                    success: function(response){
                        console.log(response);
                    },
                    error: function(jqXHR, textStatus, errorThrown){ 
                        console.log(JSON.stringify(jqXHR));
                        console.log("AJAX error: " + textStatus + + ' : ' + errorThrown);
                    }
                });
            });
        });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trumbowyg is not a function | Javascript Error - Stack Overflow
Solution was adding $.noConflict(); to the first line after the definition of the function inside of the document ready call.
Read more >
Uncaught TypeError: $(...).trumbowyg is not a function
Hi there, I am trying to add an editor to my page and I am getting the following error: startup.js:7Uncaught TypeError: $(...).trumbowyg is ......
Read more >
Error: Is not a function - Laracasts
Hey guys, I am using trumbowyg to deliver a richtext-editor on my website, to save changes I´ve implemented a function to observe the...
Read more >
Documentation | Trumbowyg: A lightweight WYSIWYG editor
Trumbowyg is a jQuery plugin for create WYSIWYG editor. ... If your problem is not solved by these tips, check the SVG icons...
Read more >
Top Trumbowyg Alternatives in 2022 - Slashdot
Compare ratings, reviews, pricing, and features of Trumbowyg alternatives in 2022. ... HTML-NOTEPAD does not function as a "webpage editor". It is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found