Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox spell check fires tbwchange but content does not update until manual input #1444

Open
Duberry opened this issue Feb 24, 2024 · 2 comments
Labels
bug:core Bug in core (trumbowyg.js)

Comments

@Duberry
Copy link

Duberry commented Feb 24, 2024

When I perform a spellcheck in Firefox, tbwchange fires.
However, if I get editor content using $('#my_trumbowyg_id').trumbowyg('html'), the value returned is the content of the editor before I ran the spell check.

If I enter any additional content in the editor manually, then $('#my_trumbowyg_id').trumbowyg('html') begins to return the correct value.

Description

  • Firefox 123.0

How to reproduce?

$('#my_trumbowyg_id').trumbowyg().on('tbwchange', function() {console.log('change');});

Type misspelt string

  • Console logs lots of changes

Use spell check to correct string spelling

  • Console logs 'change'

console.log($('#my_trumbowyg_id').trumbowyg('html'))

  • Console logs the editor content still including the original misspelt string

Type a space after the correctly spelt string displaying in the editor

$('#my_trumbowyg_id').trumbowyg('html')

  • Console logs the correct editor content.
@Duberry Duberry changed the title Firefox spell check fires tbwchange but content does not post Firefox spell check fires tbwchange but content does not update until manual input Feb 24, 2024
@Alex-D Alex-D added the bug:core Bug in core (trumbowyg.js) label Mar 3, 2024
@Duberry
Copy link
Author

Duberry commented Mar 13, 2024

Hi Alex-D. I see you have tagged this as a bug. Do you have any feedback on when it might be resolved or a pointer for the code causing it so that I could look at a fix?

@Duberry
Copy link
Author

Duberry commented Apr 4, 2024

Quick Fix is to add this jQuery extension:

(function($) {
    // Extend jQuery to include a function to get Trumbowyg content
    $.fn.getTrumbowygContent = function() {
        // Find the closest '.trumbowyg-box' parent to ensure we're working within a Trumbowyg editor
        var trumbowygBox = this.closest('.trumbowyg-box');
        if (trumbowygBox.length) {
            // If a '.trumbowyg-box' is found, find the '.trumbowyg-editor' within it to get the content
            var editor = trumbowygBox.find('.trumbowyg-editor');
            return editor.html(); // Return the HTML content of the 'trumbowyg-editor'
        } else {
            // If no '.trumbowyg-box' parent is found, log an error and return an empty string
            console.error("No Trumbowyg editor found in the ancestor elements.");
            return '';
        }
    };
})(jQuery);

Then when you want to retrieve the Trumbowyg content, call $('#your_textarea_id').getTrumbowygContent()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:core Bug in core (trumbowyg.js)
Projects
None yet
Development

No branches or pull requests

2 participants