Problem/Motivation

We have often the requirement, that the maxlength js is enabled on a field, because the editor has to check the length of a text visually, but the maxlength attribute should not be set (hard stop on the defined number of chars).

Often the editor writes more text as allowed by maxlength and then he removes/changes some words to match the max allowed length.

Proposed resolution

Add a setting per field like "Do not restrict maxlength on writing".

I will provide a patch for that.

Comments

weri’s picture

Status: Active » Needs review
StatusFileSize
new3.4 KB

Patch added.

eelkeblok’s picture

I was also looking for this functionality, (something similar to what happens when composing Tweets, where the counter will simply go to negative numbers when crossing the treshold, which basically allows you to first do a braindump, and then later edit to fit in the limits). However, I expected the setting "Force text truncate" ("Check this option if you want that the html (or the text) that the user inserts into the field to be truncated.") to do this.

From the code, it seems to do something quite similar to this; for items with a maxlength attribute (text inputs, presumably), it removes this attribute, causing the browser to stop enforcing the limit (correct me if I am wrong). Instead, it moves the validation to a validation hook, so that the limit is "soft enforced", i.e. only once you attempt to submit the value you get a validation error, instead of the browser stopping you to enter too many characters in the first place. However, I have a textarea field and on this, it doesn't seem to do anything (which kind of makes sense if the above is the only thing it does; textareas do not have a maxlength attribute).

Does it make sense to have this setting "double" as the switch for getting the functionality we are looking for here, since that effectively is for textareas what this already does for text inputs? Or am I missing something?

chasingmaxwell’s picture

Version: 7.x-3.0-beta1 » 7.x-3.x-dev
Issue summary: View changes
StatusFileSize
new3.76 KB

I agree that the "Force text truncate" option (unchecked) should provide this functionality - and it does in some cases. The issue is that the maxlength="" attribute is being used and in most browsers this will prevent the user from entering anything beyond the limit before it gets to this module's JavaScript. I'm attaching a patch which uses a data-maxlength="" attribute instead which causes the "Force text truncate" option to work as intended.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

#3 works for me with 7.x-3.2

logaritmisk’s picture

Re-roll for latest dev (9bbeb4b49ad624e38cd68e0d11514456b73ab080)

wiredescape’s picture

I feel this option is very important.
Any chance of this being re-rolled for 8.x?
Much appreciated!

Xilis’s picture

StatusFileSize
new15.11 KB
new15.25 KB

Patch #5¸ breaks the module for normal text fields (screenshots below).

The screenshots are from a basic add content form (adding a new article which has 2 additional fields: text field and text area).

Before patch:
Before applying patch #5.

After patch:
After applying patch #5.

albert volkman’s picture

@WiredEscape this is already an option in the D8 version. Simply don't check "Force truncate" in the widget settings.

albert volkman’s picture

Version: 7.x-3.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new6.97 KB

I think I may have misspoken earlier. The feature works... but I don't believe it's intentional. Here's a patch to resolve on 8.x first.

Status: Needs review » Needs work

The last submitted patch, 9: maxlength-do_not_user_maxlength_attribute-1841028-9.patch, failed testing.

albert volkman’s picture

Status: Needs work » Needs review
StatusFileSize
new7.54 KB

Fixing PHP notices.

Status: Needs review » Needs work

The last submitted patch, 11: maxlength-do_not_user_maxlength_attribute-1841028-10.patch, failed testing.

albert volkman’s picture

Status: Needs work » Needs review
StatusFileSize
new6.97 KB

It'd help if I actually made the correct patch...

Status: Needs review » Needs work

The last submitted patch, 13: maxlength-do_not_user_maxlength_attribute-1841028-13.patch, failed testing.

bgilhome’s picture

StatusFileSize
new16.29 KB

I didn't find this issue until after I'd done more or less the same thing ... I added the option for a 'soft limit' number field, and '@softlimit' & '@softremaining' tokens for the label.

In terms of UX it may be a little overkill ... but FWIW here's the patch.

5n00py’s picture

Patch from #13 better for me. It more simple than #15 and more easy to review, test and commit.

Maybe we can finish #13 patch than create followup issue for #15?

What we actually need to complete work on #13 ?

ultimike’s picture

#13 is working great for me - I vote that it gets committed.

-mike

5n00py’s picture

larowlan’s picture