-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Inconsistent string length limits on frontend and backend #1012
Comments
Great point on emoji's hadn't even considered that would be a difference in behaviour. As for showing negative numbers, it shouldn't ever be the case as we use the But interestingly, Fixed for the next release. To get this early, change your
Then run |
Actually, upon further reflection, this might be tricky. The reason being is that the string length actually differs from input (and JS, client-side checks) to saving it. We need to translate:
to
In order for it to save correctly in some database engines. As you can see, the length is different once we get to server-side validation to actually save it to the database. Respectively, the byte length above is Instead of using Litemoji, we could use
Which would make the length of this emoji 9 instead of the native 2. I'll have to give this some further thought. |
Alright, I think I've figured out a way to make this work. The only downside is an emoji now "weighs" 9 characters long. There's nothing we can do about this I'm afraid, as we store the emoji as a HTML entity ( This should now be at least using the same values client and server side. |
thanks for looking into this! not sure what the solution you came up with entails, just wanted to mention that I don't think the problem is restricted to emojis only, as there's a bunch of utf8 characters that use more than one byte: edit: ah, I see you replaced |
Yep, I believe that should be factored in. I've actually just made one more final fix. On the server-side we now use And on the front-end, we do the same thing, thanks to a nifty function. So - very long answer, but we should be sorted now. 😅 |
Fixed in 1.6.6 |
Describe the bug
Similar to the recently fixed
file size calculation mismatch for File Upload fields and server-side validation.
this one is about the charcter count mismatch.The server implementation uses
strlength
which counts bytes, the frontend usesinnerHtml.length
which counts characters.For multi-byte UTF8 characters there's a mismatch between both.
Steps to reproduce
Form settings
Craft CMS version
3.7.50
Plugin version
1.6.4
Multi-site?
No response
Additional context
https://github.com/verbb/formie/blob/craft-4/src/web/assets/frontend/src/js/fields/text-limit.js#L40-L42
Personally, I'd rather see a negative value here if something went wrong, instead of forcing it to display
0
. It might lead to more confusion on the user side, if it incorrectly displays0
The text was updated successfully, but these errors were encountered: