Fix: Strip formatting when pasting into builder title fields#3093
Fix: Strip formatting when pasting into builder title fields#3093faisalahammad wants to merge 4 commits intogocodebox:devfrom
Conversation
Fixes gocodebox#3058 When a lesson has an attached quiz, students who mark the lesson as incomplete can now re-mark it as complete without retaking the quiz, provided they have already met the quiz requirements. Changes: - Modified llms_show_mark_complete_button() to check quiz completion status - Added 4 new unit tests for quiz completion scenarios
Adds a paste event handler for contenteditable elements that do not have the data-formatting attribute. This ensures that lesson, quiz, and section titles receive plain text when users paste formatted content from external sources. Fixes gocodebox#3057
|
@faisalahammad This also seems to work well. Could you remove the "mark complete" changes from this PR? Also, can a changelog be added to this and the mark complete PR? This can be added with
or manually adding a .yml in the Thanks! |
|
Hi @brianhogg |
|
@faisalahammad Thanks for removing the code from the other PR! We'll just need to add a yml changelog file here as well, if you're able. |
|
Hi @brianhogg, I'm a bit confused since this is my first time. Could you please manage it for me or guide me so I can try myself? Thank you! |
|
@faisalahammad No problem! We would just need a .yml file similar to the one added in the other PR: I don't believe I'm able to push this up on your PR. If it's not added no worries, I can make a note to add it if/when the PR is merged into |
|
Hi @brianhogg, |

Summary
This PR fixes an issue where pasting formatted text into Lesson, Quiz, or Section title fields in the Course Builder retains HTML formatting instead of converting to plain text.
Fixes #3057
Problem
When users copy text from external sources like Microsoft Word, Google Docs, or web pages and paste it into builder title fields, the HTML formatting (bold, colors, fonts, etc.) is preserved. This creates unexpected styling in titles that should be plain text.
Why This Happens
The Course Builder uses the
_Editable.jsmixin to handle inline editing. This file already has a paste handler that strips formatting:The
on_pastefunction correctly extracts plain text from clipboard:The problem: Title inputs in builder templates do NOT have the
data-formattingattribute, so the paste event never fires for them.Affected Templates
data-formatting?lesson-settings.phpquiz.phpsection.phpquestion-choice.phpSolution
Add a second paste event that targets contenteditable
.llms-inputelements that do NOT have thedata-formattingattribute.Before
After
How It Works
Elements with
data-formatting: Continue to work as before. The paste handler strips all tags except allowed ones (likeb,i,u).Elements without
data-formatting(title fields): Now also trigger the paste handler, which extracts plain text usingclipboardData.getData('text/plain')and inserts it without any HTML.The selector
[contenteditable]:not([data-formatting])ensures we only target editable fields that should receive plain text.Testing Instructions
Manual Testing
Go to WordPress Admin > Courses > Edit any course > Course Builder
Test Lesson Title:
Test Quiz Title:
Test Section Title:
Regression Test - Question Choices:
data-formattingattributeHow to Get Formatted Text for Testing
Technical Details
File Changed
assets/js/builder/Views/_Editable.jsChange Size
Backward Compatibility
This change is fully backward compatible:
data-formattingcontinue to work exactly as beforeRelated Issues
Changelog Entry