r13374 - in Products.Archetypes/trunk: . Products/Archetypes/skins/archetypes/widgets Products/Archetypes/skins/archetypes/widgets/js

"Tom Gross" <[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: tom_gross
Date: Mon Dec 20 13:20:07 2010
New Revision: 13374

Modified:
   Products.Archetypes/trunk/CHANGES.txt
   Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/js/textcount.js
   Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/textarea.pt
Log:
Fixed textCounter JavaScript to work with fieldnames with hyphen.
https://dev.plone.org/plone/ticket/11334


Modified: Products.Archetypes/trunk/CHANGES.txt
==============================================================================
--- Products.Archetypes/trunk/CHANGES.txt	(original)
+++ Products.Archetypes/trunk/CHANGES.txt	Mon Dec 20 13:20:07 2010
@@ -32,6 +32,12 @@
 - Depend on Zope 2.13.1
   [tom_gross]
 
+- Fixed textCounter JavaScript to work with fieldnames with hyphen.
+  API of textCounter-method changed. Second parameter takes now
+  the name of the counterfield, not the DOM object itself.
+  https://dev.plone.org/plone/ticket/11334
+  [tom_gross]
+
 1.6.4 - 2010-11-06
 ------------------
 

Modified: Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/js/textcount.js
==============================================================================
--- Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/js/textcount.js	(original)
+++ Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/js/textcount.js	Mon Dec 20 13:20:07 2010
@@ -1,19 +1,13 @@
 <!-- Original:  Ronnie T. Moore -->
 <!-- Dynamic 'fix' by: Nannette Thacker -->
-
 function textCounter(field, countfield, maxlimit) {
-
-	if (field.value.length > maxlimit) {
-	
-		// if too long...trim it!
-		field.value = field.value.substring(0, maxlimit);
-		
-        alert( 'This field is limited to ' + maxlimit + ' characters in length.' );
-        		
-	} else {
-	
-		// otherwise, update 'characters left' counter	
-		countfield.value = maxlimit - field.value.length;
-		
-	}
-}
\ No newline at end of file
+  var fieldval = jq(field).attr('value');
+  if (fieldval.length > maxlimit) {
+      // if too long...trim it!
+      jq(field).attr('value',  fieldval.substring(0, maxlimit));
+      alert( 'This field is limited to ' + maxlimit + ' characters in length.' );
+  } else {
+      // otherwise, update 'characters left' counter	
+      jq('input[name="' + countfield + '"]').attr('value', maxlimit - fieldval.length);
+  }
+}

Modified: Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/textarea.pt
==============================================================================
--- Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/textarea.pt	(original)
+++ Products.Archetypes/trunk/Products/Archetypes/skins/archetypes/widgets/textarea.pt	Mon Dec 20 13:20:07 2010
@@ -32,7 +32,8 @@
                   content_length python:len(content);
                   append_only python: getattr(widget, 'append_only', None);
                   maxlength python: getattr(widget, 'maxlength', None);
-                  keypress string:textCounter(this, this.form.textCounter_${fieldName}, ${maxlength});">
+                  tcname string:textCounter_${fieldName};
+                  keypress string:textCounter(this, '${tcname}', ${maxlength});">
 
         <textarea
             class="blurrable firstToFocus"
@@ -56,7 +57,7 @@
                        i18n:name="count"
                        tal:define="remaining python:(int(maxlength) - content_length) + content.count('\n');
                                    inputsize string:4"
-                       tal:attributes="name string:textCounter_${fieldName};
+                       tal:attributes="name tcname;
                                        value remaining;
                                        maxlength inputsize;
                                        size inputsize;

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.