Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
When a user pastes text more then that Maxlength setting a lot of JS errors appear in the console and prevents the user from editing within the text field..
Console JS errors:
Uncaught TypeError: Cannot set property 'contentEditable' of null
at $.a (ckeditor.js?v=4.6.2:773)
at ckeditor.js?v=4.6.2:26
Steps to Recreate
- Set a Maxlength limit on a rich text field
- Enable the Force Truncate option
- Do not enable the Safe truncate HTML option
- Paste text that exceeds the character limit set on the field
Proposed Resolution
If we decide to implement #3230544: Apply safe truncate HTML behavior by default on rich text fields then that will resolve this issue.
If we decide not to implement that feature then consider incorporating the patch submitted.
Comment | File | Size | Author |
---|---|---|---|
#19 | maxlength-chrome-paste-test.gif | 135.66 KB | cedewey |
#14 | eternal_limit_check-2891186-14.patch | 1.83 KB | i-grou |
#13 | maxlength-select-text.gif | 106.11 KB | i-grou |
#12 | eternal_limit_check-2891186-12.patch | 1.35 KB | i-grou |
#10 | text_is_too_long.gif | 109.44 KB | i-grou |
Comments
Comment #2
Ujval Shah CreditAttribution: Ujval Shah as a volunteer commentedHi anpolimus,
Please provide steps to re-produce the issue.
Thanks,
Ujval
Comment #3
anpolimus@Ujval Shah
1. Configure field to have maxlength limit
2. Try to paste large text to this field.
3. Try to edit this field value after pasting.
4. Explore errors at the console and slow browser.
Comment #4
anpolimusComment #5
mr.baileysI'm unable to reproduce this on simplytest.me with the following steps (using maxlength-1.0-beta2):
No javascript error is reported using the above steps. I tried both with and without the "Bypass maxlength setting"-permission.
@anpolumis: can you still reproduce this issue on a stock D8 with maxlength-1.0-beta2 enabled?
Comment #6
alduya CreditAttribution: alduya at 2DotsTwice bvba commentedI experienced the same problem with both the beta1 and current dev version. But it only when using Google Chrome, not in Firefox or Safari.
It looks as if the JS keeps evaluating the length and moving the cursor to the start of the text. Again and again.
It happens both when pasting to long text or typing more than the text limit.
Comment #7
alduya CreditAttribution: alduya at 2DotsTwice bvba commentedComment #8
alduya CreditAttribution: alduya at 2DotsTwice bvba commentedSorry, after coming back to work today and restarting everything I noticed that with the dev version there is also no problem in chrome.
Could someone maybe create a new beta release. The current one is pretty old.
Comment #9
Dafydd Owen CreditAttribution: Dafydd Owen commentedTried both the beta and dev versions of the module with this issue present in both for me in chrome. As a quick fix I commented out the lines 314-316 (below) in maxlength.js and all seems well.
Comment #10
i-grou CreditAttribution: i-grou as a volunteer commentedHave another issue here: when user pastes text that exceeds the limit page freezes. No errors in console - just can see how the text editor is shaking and then page freezes and I can't edit any fields:
After some investigation I've found out that there is an eternal loop caused by lines 323-325 (probably this event is triggered several times and then it becomes eternal loop):
Any ideas how to solve it?
FYI - text field configuration:
Max length: 350
Force truncate: true
Safe truncate html: true
Comment #11
i-grou CreditAttribution: i-grou as a volunteer commented[this comment should be ignored, see the next one]
Comment #12
i-grou CreditAttribution: i-grou as a volunteer commentedHere's a patch that fixes eternal check loop.
The idea is this: to avoid eternal loop and freezing let's get time of this update and then stop execution if previous update was executed just now.
P.S. In most cases it works ok, but some times if user would hit all keys possible (including Ctrl+V) very fast and click mouse buttons at the same time - editor would freeze the page again... Would not investigate more for now, as this patch satisfies me, and I'm not sure that this bug is caused by maxlength module only.
Comment #13
i-grou CreditAttribution: i-grou as a volunteer commented[this comment should be ignored, see the next one]
Comment #14
i-grou CreditAttribution: i-grou as a volunteer commentedWell there still was another bug - it was not possible to select a text using mouse:
It processes the text on mouse down event and when the character limit is reached the text processing may behave not as expected. I believe that maxlength thinks that text length exceeds the X characters limit (because it has html tags) and then performs processing to reduce the text length. Text is not reduced, because html tags are striped and length is recalculated during processing, but it updates editor content any way. That’s why it was not possible to select a text using mouse.
So previous patch was improved to check if content is different and stop unwanted processing if not.
Comment #15
wombatbuddy CreditAttribution: wombatbuddy commentedAs a workaround, the 'CKEditor Wordcount' module can be used instead. It works good with the CKEditor.
Comment #16
i-grou CreditAttribution: i-grou as a volunteer commentedThanks @wobatbuddy for suggestion. However it seems to me that module does not provide any validation features, so it may require some extra coding to make it work as expected.
Comment #17
i-grou CreditAttribution: i-grou as a volunteer commentedIs there a chance that patch above would be added to the module in the nearest future? Or some other solution would be implemented?
Comment #18
mlncn CreditAttribution: mlncn at Agaric for Drutopia, Portside, Teachers with GUTS commentedComment #19
cedeweyanpolimus,
Thank you for reporting this.
ivanklochko,
Thank you for taking the time to write a patch for this.
I tested Maxlength 8.x-1.0-rc1 with Drupal 8.9.18 on Chrome Version 92.0.4515.159 (Official Build) (64-bit) using Elementary OS 5.1.7 Built on Ubuntu 18.04.4 LTS.
I could not reproduce the error you describe, including the last issue you reported of not being able to select text.
Here is a screencast of what I saw.
Comment #20
cedeweyComment #21
cedeweySince I can't reproduce this issue and we haven't received more info from others, I'm going to close this.
Comment #22
cedeweyOk, I was able to recreate this issue after all. I needed to leave "Safe Truncate HTML" off.
This is postponed because we may just apply that Safe Truncate HTML automatically to rich text fields, which would then resolve this issue.
#3230544: Apply safe truncate HTML behavior by default on rich text fields
I've also updated the original ticket description with more clear steps to reproduce.
Comment #23
cedeweyI'm closing this since we are moving forward with #3230544: Apply safe truncate HTML behavior by default on rich text fields, which renders this issue obsolete.