I need this module because I need to see the number of characters in the field, but I don't need to limit the length. I can specify maxlength as 99999 or something, but I would like to be able to just display the counter in the desired field. Thank you!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Title: Unlimited field. Just a count! » Unlimited field, just a character count
Component: Code » User interface
Related issues: +#1918738: Character count on fields via Maxlength integration (D7)

That would be useful for integration with e.g. Metatag (#1918738: Character count on fields via Maxlength integration (D7)).

JeroenT’s picture

Status: Active » Needs review
FileSize
1.79 KB

I created a simple initial patch for this. I added a new element to the form 'maxlength_js_limit'.

How to test? Add maxlength_js and maxlength_js_limit to your form element :

$form['foo'] = array(
'#type' => 'textfield',
'#maxlength_js' => TRUE,
'#maxlength_js_limit' => 150,
);

I add the 'maxlength_js_limit' as a data-attribute on the form element and in javascript, I check if this data-maxlength-js-limit attribute exists. When it exists, I set the enforce option to false.

What do you think? Any suggestions?

seanB’s picture

Status: Needs review » Reviewed & tested by the community

Seems to work fine! +1

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs work

One minuscule thing - the "if" statements should have a space after them for both files to match the Drupal coding standards.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
1.79 KB
1.05 KB

Added the code styling updates.

JeroenT’s picture

Status: Needs review » Reviewed & tested by the community
weri’s picture

DamienMcKenna’s picture

@weri: The link you provided was to this issue, did you mean to link to a different one?

weri’s picture

Thank you @DamienMcKenna for the hint!! I linked now the correct issue.

cedewey’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

We are putting a feature freeze on the Drupal 7 version of the module, so I'm marking this Closed, won't fix. Thank you everyone for working on this issue. If you do want to maintain the Drupal 7 version, do reach out. We'd be happy to bring you on board as a maintainer.

Also, this is a feature that exists in the Drupal 8/9 version so I do encourage people to upgrade to Drupal 8/9 and enjoy this enhancement along with the many other benefits of the latest version of Drupal.