Download & Extend

Desire Counter to Go into Negative Rather than Prevent Data Entry

Project:Maxlength
Version:6.x-2.0-beta1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

I would much prefer the counter go into negative numbers than behave as it does currently, stopping any further data entry upon reaching its limit. I'd much rather the form throw an error on submit, "You need to limit the title field to 140 characters."

As a writer, it is much easier for me to edit down when I can see the whole text in front of me.

A previous version of Maxlength had the counter at "0" but still allowed further data entry. I'm sure that was deemed a big and fixed, though I preferred that to having the from stop me from further data entry.

Ideally this could be a configurable setting, but of course that's more work.

Anyway, great module, just thought I'd vote for the js tool going into negative numbers.

Shai

Comments

#1

Ok this would be definitive a feature, then the validation on form submit should handle the length.

#2

I agree, that's what I'm looking for. Also it's the way to go with cut and paste text.

#3

as I expected it's an easy fix if you need it right away.
Just comment out the following lines (10-13) in maxlength.js

//if (remainingCnt < 0) {
//  field.val(field.val().substr(0, limit));
//  remainingCnt = 0;
//}

#4

I set this up to change colors of the text and show an error when the maxlength is exceeded. It also allows the maxlength to be exceeded in case someone pastes in data so that none of it is lost.

AttachmentSize
maxlength-exceed-limit.patch 2.44 KB

#5

Status:active» needs work

+++ maxlength.js 9 Jul 2010 18:39:38 -0000
@@ -1,19 +1,23 @@
+  var color = $(".maxlength-counter").css('color');//'#659801';

The color schould be configurable.

+++ maxlength.js 9 Jul 2010 18:39:38 -0000
@@ -1,19 +1,23 @@
+    message = '<div class="maxlength-message">You have exceeded the maximum characters for this field!</div>';

This should be trasltable

+++ maxlength.js 9 Jul 2010 18:39:38 -0000
@@ -21,19 +25,19 @@ Drupal.maxLength_change = function () {

-if (Drupal.jsEnabled) {
-  $(document).ready(function(){
-    // get all the settings, and save the limits in the fields
-    for (var id in Drupal.settings.maxlength) {
-      var limit = Drupal.settings.maxlength[id];
-      var element = $("#"+ id);
-      element.attr("limit", limit);
-      // update the count at the page load
-      Drupal.maxLength_limit(element);
-
-      element.load(Drupal.maxLength_change);
-      element.keyup(Drupal.maxLength_change);
-      element.change(Drupal.maxLength_change);
-    }
-  });
+
+Drupal.behaviors.maxLength = function(context) {
+  // get all the settings, and save the limits in the fields
+  for (var id in Drupal.settings.maxlength) {
+    var limit = Drupal.settings.maxlength[id];
+    var element = $("#"+ id);
+    element.attr("limit", limit);
+    // update the count at the page load
+    Drupal.maxLength_limit(element);
+
+    element.load(Drupal.maxLength_change);
+    element.keyup(Drupal.maxLength_change);
+    element.change(Drupal.maxLength_change);
+  }

You should write against the latest cvs version.

Powered by Dreditor.

#6

Status:needs work» active

@kleinmp,

Thank you SO much. This is exactly what I wanted.

I applied the patch in #4 against Maxlength 2.0 beta 1 and it works as you described.

However, there is one (not so important) part that is broken:

If the user ignores the red text and ignores that the counter going has gone into negative territory and clicks "Save" anyway, Drupal throws a validation error giving feedback that the offending data in the maxlength affected field is too long. The screen redraws with all of the data preserved. But the js is now absolutely dead. The counter shows, in black, the value you had set for the number of characters. It will not count down or do anything.

Personally, I don't think this is such a big deal... it's about providing convenience... and this user has flagrantly ignored the UI which has given great feedback. So okay, the user now doesn't have use of the widget anymore.

I'm such a super-novice at JS that I didn't check out your code. If the problem I reported is easy to fix, that would be great. If not... I would still advocate for committing the patch to the module, or incorporating it as a setting choice. The module would be a much more sophisticated implementation of a countdown widget.

Shai Gluskin

#7

Status:active» needs work

.

#8

When a form fails validation, the javascript added through form alters seems to fail. I think that it may be because the form is now pulled from the form cache and it doesn't actually go through the entire form_alter process. There is a similar issue with css.

This is probably why the maxlength js is not working after failing validation.
In the past, I've had to fix this by adding javascript in with my theme instead of on form_alter, but this issue goes beyond this module, and I'd be curious if anybody has a good solution for it.

#9

+1