I have noted that when there are linebreaks (return), the counter allows the user to continue till max is reached ... seems fine ... but on submission, it fails since the counter apparently hasn't been counting the linebreaks. This is likely to cause confusion in some cases.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | maxlength.module.txt | 12.68 KB | betoaveiga |
Comments
Comment #1
cleverhoods commentedsubscribe, here is the same issue.
Comment #2
noemi commentedSame issue.
Comment #3
stickgrinder commentedI think it's due to the fact that Drupal check for number of character after converting the field content to filtered HTML. Line breaks all become
<br />so the count is screwed up.Just a guess but I'm in the same situation here...
Comment #4
a_c_m commentedI just tested this and can confirm it's failing.
#3 your close, but not 100% right. The carriage return is stored as 2 or more chars (http://en.wikipedia.org/wiki/Newline)
Patch now in 6.x-2.x to fix this (http://drupal.org/cvs?commit=312470)
Comment #6
cleverhoods commentedJust a remark: we need to do the same validation at the _maxlength_format_element function (line 175) too otherwise the module will not work properly at the edit page.
Example: if I have an enabled countdown at the node body (max length: 250) and if I fill out 240 from it than push 4 times the return and i fill out the remaining characters the module will return an error message (the body truncated to 250 charater) and cut down the end of the text.
Comment #7
a_c_m commentedI see what you mean.
Only thing to do is count newlines at 2chars at the countdown level - but that will confuse users.
Suggestions and patches on how to fix this are welcome.
Comment #8
cleverhoods commentedHi
My solution was - I think - simple:
start: line 175
And i put your code there
Actually I really don't know how to create a patch... otherwise I would create one for my http://drupal.org/node/643828 issue :)
Comment #9
a_c_m commentedLooks good, making patches is a worth while learning investment !
It helps module contributors apply your work - i know it may feel like a pain, but i, or any other busy module maintainer, are unlikely to get the time to review the improvements unless they are in an easy to test/implement format.
There is a lot of documentation around on the subject.
http://drupal.org/patch/create
Comment #10
cleverhoods commentedaww... oh well... sooner or later I must to learn it to be sure.
I think I will have some time for this at afternoon
Comment #11
cleverhoods commentedsorry guys... I was really lazy ^^ Patch will arive at the weekend ^^
Comment #12
jmcoder commenteda_c_m I'd like to thank you for your work on this module and for keeping up on this issue. Maxlength is a very, very important module for sites that are picky about formatting, I am finding myself installing it standard & usually finding some reason to implement it, even in rather simple sites. Good job a_c_m.
Comment #13
betoaveigaBased on lavjaman #8 I changed maxlenght.module file, but doesn't work as I hope.
Probably because I'm using the new beta1 version.
However, I had the same problem of "not counting linebreaks properly".
I added some lines in the function maxlength_nodeapi(), close to line 240:
BEFORE:
AFTER:
That counts linebreaks right for me. This solution is based on lavjaman #8, obviously.
BTW, it saves content right.
Hope that helps someone.
Comment #14
a_c_m commentedLooks good, making patches is a worth while learning investment !
It helps module contributors apply your work - i know it may feel like a pain, but i, or any other busy module maintainer, are unlikely to get the time to review the improvements unless they are in an easy to test/implement format.
There is a lot of documentation around on the subject.
http://drupal.org/patch/create
Comment #15
tobiberlinI copied the code from the dev version to get the above lines of code working but still the behavior of maxlength is a little bit strange - linebreaks are not counted correctly so that the user is told that a few character are still remaining but if the node is saved an error message appears.
Comment #16
betoaveigaHi all... I'm using Beta version right now...
I had made some quick modifications to the module file in order to:
- Count linebreaks correctly
- Work with #after_build (count characters after the form validation fails)
For me it's working, that's why I'm uploading my module file...
BTW, it works for node & title, I'm not using CCK. I tested CCK fields but it didn't work.
Hope this helps.
PD: Don't forget to delete the 'txt' extension.
Comment #17
aron novakit seems that something like #16 is already committed to the CVS.
Comment #18
aron novakThere is support now for CCK fields: http://drupal.org/cvs?commit=501066
The thing is that i added a separate configuration field on the field edit page, so it's possible to set maxlength limit and cck max_length limit separately! So it's possible to set CCK's limit to 0 and maxlength's limit to something else, so maxlength is able to validate the length in a more sophisticated way. It's a bit not user friendly, but i had no better idea to "override" CCK's validation on the length. Any thoughts?
Comment #19
papasse commentedTested that last commit, it works as expected. This problem seems to be more of a CCK issue, if this module count linebreaks as 2 characters...
Comment #21
frankfarm commentedI'm using Maxlength 6.x-2.0-beta2 in Drupal 6.26 and am encountering this problem. Specifically, if my text entry has 3,982 characters and 18 carriage returns and a 4,000-character limit, the Javascript says, "Content limited to 4000 characters, remaining: 18" which is incorrect -- it should say zero remaining. Which is the correct patch or workaround to implement to resolve it? I'm not finding it very clear from the thread above. Thanks!
Comment #22
frankfarm commentedI'm changing the status from "closed (fixed)" to "needs review" and the category from "feature request" to "bug report". Although this issue might have been fixed in the past, I believe it is not fixed with 6.x-2.0-beta2 in 6.26 and would like others to provide input on this claim. I consider this a bug because to me failing to count characters correctly (and in a way that makes sense to users) is a problem, not a feature request. This problem doesn't only cause confusion -- it generates support requests because the counter clearly says, for example, 5 characters left, but when they submit an error is presented. If there really is a fixed version somewhere and I can get it working in 6.26 I am happy to admit my mistake and declare this issue closed.
Comment #23
seandunaway commentedDuplicate #1647114: Fix JS truncate of test that contains new lines characters