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

Character limit not working #150

Closed
CharuGoyalS opened this issue Jul 18, 2024 · 4 comments
Closed

Character limit not working #150

CharuGoyalS opened this issue Jul 18, 2024 · 4 comments

Comments

@CharuGoyalS
Copy link

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
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

@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:

  • Try to prevent input of more than a certain length from the plugin itself, but that would significantly lower input performance.
  • Go through the DOM to find the Save button or the form itself and prevent the submit action if you exceed a certain length, but this is bad.
  • Ask the Strapi team to address this issue or create a PR to change the validation logic.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants