Last updated March 31, 2015. Created on October 8, 2011.
Edited by nicrodgers, jm.federico. Log in to edit this page.

D7: 7.x-3.x

Maxlength creates a new Form Property: #maxlength_js which in conjunction with #maxlength will enforce, via JavaScript, the maxlength of a textfield, a textarea, or a text_format and will show the number of characters left.

UI Usage

When editing the a text field widget's settings, you can set the character limit to be controlled with Maxlength. Widgets currently accepted are:

  • Text area (multiple rows)
  • Text area with a summary
  • Text field

Permissions

Maxlength creates a new 'bypass max length' permission. This is assigned to the Administrator role by default. Therefore, when you first install Maxlength, administrators will not see the counter.

WYSIWYG

Module is compatible with tinyMCE and CKEditor using the wysiwyg module

Code (api?) Usage

Whether when creating a form or when altering one, put both #maxlength and #maxlength_js properties on the elements you want to control.

#maxlength

Description: The maximum amount of characters to accept as input.

Values: A positive number.

#maxlength_js

Used by: textfield, textarea, text_format

Description: Indicates whether or not the field should have a reverse character counter.

Values: TRUE or FALSE

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

myselfhimself’s picture

Hello!
I had been using maxlength_js on my site so far. Disabling it and installing maxlength in place seems to make the characters limit continue working. Is maxlength truly a drop-in replacement for maxlength_js ? Are they any upgrade path instructions from maxlength_js to maxlength for making things properly and avoid a break in further maxlength updates or so?
Thanks in advance!

HAL 9000’s picture

Do not forget: superuser has all rights, if you would like to test it, use a user who has not "Bypass maxlength setting" right.