Currently there is a warning option in the jQuery plugin that allows the remaining characters to go past the limit by a certain amount.

The default for this is 10, meaning my users can go past the limit I set by 10 characters and the count goes into minus.

This is not desirable in a lot of cases so I think it should be configurable on the field (or sitewide).

Comments

Xilis’s picture

Title: Make the warning option for the jQuery plugin a configurable setting » Make the warning option a configurable setting
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new460 bytes

Here's a patch that makes the warning configurable. The only requirement was to add this line
options['warning'] = $(this).attr('warning'); in maxlength.js

If you want to alter it for your element, add a 'warning' attribute to it:
$element['#attributes']['warning'] = 100;.

The default warning is currently hardcoded to 10 in Maxlength module (in the defaults).

pmichelazzo’s picture

StatusFileSize
new31.32 KB

Xilis,

I tested your solution but, unfortunately is not working. Checking the field, the "warning" attribute is there (you can see on the screenshot attached) but nothing happens. If I print the value on the js, I just receive an "undefined" value.

Any clue?

Best

Xilis’s picture

Issue summary: View changes
StatusFileSize
new6.5 KB
new8.27 KB

Ah yes, the patch makes it possible to use the "warning" attribute on a form element to affect when the class change occurs (shown as css change).

 $form['text_field_element'] = array(
    '#type' => 'textfield',
    '#title' => 'What is Your Price?',
    '#size' => 10,
    '#maxlength' => 50,
    '#maxlength_js' => TRUE,
    '#required' => TRUE,
    '#attributes' => array(
      'warning' => 25,
    ),
  );

So this is before the warning css kicks in:
Screenshot of textfield without warning css
And after:
Screenshot of textfield with warning css

jenlampton’s picture

Title: Make the warning option a configurable setting » Make the number of characters over the limit a configurable setting

Updating issue title

cedewey’s picture

Status: Needs review » 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.

pmichelazzo’s picture

Hi @cedewey

If you want, I can help with the project.

cedewey’s picture

Hi pmichelazzo,

That's great to hear, we'd be happy to have your help.

I'll message you directly to coordinate further. Thanks!