Products.Archetypes/master: Merge pull request #93 from plone/vkarppinen/textcount
GitHub <jenkins-z4DKO/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.cvs |
|---|---|
| Message-ID | <[email protected]> |
Repository: Products.Archetypes Branch: refs/heads/master Date: 2017-07-10T12:37:10+02:00 Author: Maurits van Rees (mauritsvanrees) <[email protected]> Commit: https://github.com/plone/Products.Archetypes/commit/4b4699588be90ba2aa8d8bcfb4c56a0670fe99e3 Merge pull request #93 from plone/vkarppinen/textcount Fix bugs with old jquery version and textlimit alert Files changed: M CHANGES.rst M Products/Archetypes/skins/archetypes/widgets/js/textcount.js diff --git a/CHANGES.rst b/CHANGES.rst index ef472c6b..8d33c44e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,13 @@ New features: Bug fixes: +- Fixed textcount.js support jquery>1.6. + [vkarppinen] + +- Fixed a bug (that it was possible to enter text length over maxlimit) + by replacing maxlimit alert() with highlighting textcountfield. + [vkarppinen] + - Prevent AttributeError on deleting a Reference from a object that is gone. Fixes https://github.com/plone/plone.app.contenttypes/issues/41 [pbauer] diff --git a/Products/Archetypes/skins/archetypes/widgets/js/textcount.js b/Products/Archetypes/skins/archetypes/widgets/js/textcount.js index 48c9a85f..b09ff827 100644 --- a/Products/Archetypes/skins/archetypes/widgets/js/textcount.js +++ b/Products/Archetypes/skins/archetypes/widgets/js/textcount.js @@ -1,12 +1,15 @@ -<!-- Original: Ronnie T. Moore --> -<!-- Dynamic 'fix' by: Nannette Thacker --> +// Original: Ronnie T. Moore +// Dynamic 'fix' by: Nannette Thacker function textCounter(field, countfield, maxlimit) { - var fieldval = jQuery(field).attr('value'); + var fieldval = jQuery(field).val(); + var counterElem = jQuery('input[name="' + countfield + '"]'); if (fieldval.length > maxlimit) { - // if too long...trim it! - jQuery(field).attr('value', fieldval.substring(0, maxlimit)); - alert( 'This field is limited to ' + maxlimit + ' characters in length.' ); - } - // update 'characters left' counter - jQuery('input[name="' + countfield + '"]').attr('value', Math.max(maxlimit - fieldval.length, 0)); + // if too long...trim it! + jQuery(field).val(fieldval.substring(0, maxlimit)); + counterElem.css('border-color', 'red'); + } else { + counterElem.css('border-color', '#ccc'); + } + // update 'characters left' counter + counterElem.val(Math.max(maxlimit - fieldval.length, 0)); } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot