nshenderov / strapi-plugin-ckeditor

Integrates CKEditor 5 into your Strapi project as a fully customizable custom field.
https://www.npmjs.com/package/@_sh/strapi-plugin-ckeditor
MIT License
103 stars 58 forks source link

Character limit not working #150

Closed CharuGoyalS closed 3 months ago

CharuGoyalS commented 4 months ago

apply character limit of 5000 to ckEditor.

Expected Result : it should not allow more than 5000 characters.

Actual Result : it is accepting more than 5000 characters.

crfts-tun commented 3 months ago

I've got the same problem. I applied a limit of 60 characters, but as you can see, it exceeds 60. It's just a highlight; it can still be saved without an error.

Screenshot 2567-07-25 at 15 38 57
nshenderov commented 3 months ago

The Word count and character count feature by default is not supposed to do anything but count. If you want any special behavior, you can customize the plugin to your needs or create a feature or PR request.

CharuGoyalS commented 3 months ago

Please check this again as- it is not word count, we are setting Maximum length means it is supposed to show some error if the length is increasing. Same is working correctly in Strapi's default markdown editor and other fields.

image
nshenderov commented 3 months ago

@CharuGoyalS In short, it highlights the counter in red when you exceed the limit, and mimicking the default behavior is not currently possible due to Strapi's validation logic.

There was no good way to mimic the default behavior before. I checked again, and there is nothing new in that direction. The problem lies in the way Strapi validates the editor's output. It measures the string length directly, which works for the default Markdown editor, but in the case of CKEditor, we have a string containing HTML syntax, and elements like tags shouldn't be counted when measuring it.

It is possible to manually output an error bypassing Strapi's error logic, but preventing the save action is not an easy task. So, I went with just highlighting the counter in red.

Some thoughts:

If you have any good ideas, I would be eager to hear them.

@crfts-tun I think you mixed up the repo. Based on your screenshot, it looks like you are using the official plugin.