Support from Acquia helps fund testing for Drupal Acquia logo

Comments

loze’s picture

Title: Dosen't work with tinyMCE » Doesn't work with tinyMCE
mariuss’s picture

Can you give us some more details? What exactly happens when tinyMCE is present?

Can you also check the browser's JavaScript console, to see if there are any JavaScript issues?

loze’s picture

this is related to http://drupal.org/node/207230

with tinyMCE enabled the javascript counter doesn't update.
Presumably, if it did, it would count the html tags that the text editor adds as characters. is that correct?
You should consider supporting not counting html tags as characters in the max chars.

mariuss’s picture

Status: Active » Postponed (maintainer needs more info)

Can you please look at the JavaScript console?

loze’s picture

No errors in the console.

I dont think the onkeyup event is being triggered. or tiymce is overriding it.

a_c_m’s picture

tinymce (and other editors) do not edit the normal form input, they copy the data from the input into their own window, which they place over the original input box. Only when the form is submitted is the new data put back. Which is why we would need to use the hooks mentioned in the wiki's above.

We would also need to detect if tinymce was being used, as well as strip out any tags used.

NaX’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.43 KB

I have sort of found a way around this problem, after many hours of messing with tiny.

What I did was write a plugin for tiny as follows.

Added the directory maxlength to tinymce/jscripts/tiny_mce/plugins

I added the attached file to that dir and duplicated the file calling it editor_plugin_src.js (don’t think this is needed).

Then I added the following to plugin_reg.php in tiny’s module dir.
I placed this at the end of the file just above the return $plugins;

$plugins['maxlength'] = array();

Once this is all done you should now see a new plugin that you can activate when creating your tiny profiles called "Drupal maxlength"

Hope you find that all helpful.
PS. This is all on D5.x. I don’t know if the 6.x js is different.

mike_gie12’s picture

Version: 6.x-1.x-dev » 5.x-1.0

Hello,

I tried the module + patch and yes indeed a new plugin was added on tinymce, however, it didn't work. What tinymce version did you use for the patch?

Thanks!!

NaX’s picture

I used TinyMCE Drupal module 5.x-1.9 and TinyMCE version 2.1.3 and Maxlength 5.x-2.0-beta2.

graper’s picture

I just tried this combination. It worked with CCK text fields that had tinymce turned on, but I did have issues.

  1. Cut and Paste did not update character count
  2. making something bold, underline, or using any of the buttons that add in html did not update the character count
  3. using the link to disable the editor and editing something did not update the character count

Granville

mcload’s picture

Have the same problem with wysiwyg API with Tinymce on Druapl 6.10. Javascript couter does not work on Tinymce box.
Subscribing.

jberube’s picture

Version: 5.x-1.0 » 6.x-2.x-dev
FileSize
1.21 KB

Thanks so much for the TinyMCE plugin, NaX.

I modified it to work with TinyMCE 3.x.

First, open sites/all/modules/wysiwyg/editors/tinymce.inc. At the bottom of the file, add this just before " } return $plugins; "

$plugins['maxlength'] = array(
   'path' => $editor['library path'] .'/plugins/maxlength',
   'buttons' => array('maxlength' => t('Maxlength compatibility')),
   'internal' => TRUE,
   'load' => TRUE,
);				

Then save the attached file as sites/all/modules/wysiwyg/tinymce/jscripts/tiny_mce/plugins/maxlength/editor_plugin.js

Then enable the "maxlength compatibility" plugin in your WYSIWYG settings.

rolfmeijer’s picture

With the 3.5 version of TinyMCE the plugins path has changed. So the editor_plugin.js should be in sites/all/libraries/tinymce/jscripts/tiny_mce/plugins/maxlength.
I also noticed that this (comment #13) does not work with the 6.x-1.x-dev version of the maxlength module.

ayalon’s picture

FileSize
1.67 KB

Today I needed a proper TinyMCE support for the Maxlength plugin.

Thanks to all good ideas in this thread, I created a standalone module, that enables via wysiwyg API the Maxlentgh Support for TinyMCE.

With this module it is not necessary to edit any TinyMCE files nor adding plugins in the editors library.

Hope this help someone.

The module works with the beta2 and also with the latest dev version of maxlength.

UNarmed’s picture

Hey im giving it a try now so il report back =]

steve_uk’s picture

Could this be adapted to work with FCKeditor?

pr0test0r’s picture

Version: 6.x-2.x-dev » 6.x-2.0-beta1

Ayalon, I'm trying to use your module with Maxlength 6.x-2.0-beta1, but I can't get it to work. It's activated, and I have maxlength configured with my content type, but when I go to edit, it's the same as if I didn't have your mod installed at all. What am I missing?

ayalon’s picture

You need to activate MaxLength also under your WYSIWYG settings in the WYSIWYG API module. Did you miss the checkbox at the end of the WYSIWYG Buttons settings?

pr0test0r’s picture

Ah. Got it. I misunderstood that instruction. The "Maxlength compatibility" checkbox is under "Buttons and Plugins." Works great!

mikejonesok’s picture

Thanks for the mod. Still does not count pastes until a keyboard stroke, but it always been like that. Thanks again!

gausarts’s picture

Hi, maxlength now supports comment limit, but the plugin here doesn't work with the comment form. Any idea to make it compatible with the latest comment limit. This would be nice. See the issue here => http://drupal.org/node/572398

Thanks

gausarts’s picture

My, so sorry. I forgot to check the compat mode with comment filter. So this plugin indeed works with comment as well.

Thanks

saulalbert’s picture

Awesome, turned the plugin on in TinyMCE 3.3.6 profiles and it works like magic. aaahhhh. Thanks so much :) (using maxlength 6.x-2.0-beta1)

gordon’s picture

That wysiwyg bridge module is a bit of a pain, I have implemented as a part of the maxlength module and it works great.

I need to submit it this as a patch.

haggins’s picture

Sadly it also counts all html. Is this working as intended?

haggins’s picture

FileSize
2.04 KB

Here's a new version which first replaces all   with ' ' and then strips all tags. The function "strip_tags()" is copied from another suggestion on drupal.org which I'm not able to find again (sorry for that!).
This updated version also respects maxlength and does not allow to input longer strings.

However, this does only work 99% since sometimes you have to click around to get the counter updated. I would say it has a precision with +- 1 character.

NancyDru’s picture

Sorry for coming late to the dance. IMHO, it is simply wrong to discount the characters added by the editor, because the form's maxlength parameter is going to count them and truncate at it's limit. I encountered this issue on the user signature form element, which truncated because of those stupid editors.

NaX’s picture

@NancyDru
I don't know if I am properly understanding you but, I think both with and without the strip_tags function has merits. There are times you want to include markup and there are times you might just want it to be word counter regardless of markup. Most times I needed it to disregard markup. But I have not tried the latest version so I don't have any firsthand experience with the latest version. I think the difficult part is making sure that HTML is not broken by the max length limit. The last time I used max length with TinyMCE I also used the htmLawed module to mitigate HTML problems and broken teaser problems so I cant say if max length caused any HTML to be broken.

I have not tried using it with a user signature yet, but if I did I would also look into making max length count the users signature and behind the scenes adding it to the max count, without the user knowing. I just don't know how you would check if the user removes the signature and ends up getting access to more characters.

NancyDru’s picture

Well, my most immediate use of this is on a very fragile D5 site, so I am reluctant to even try it. I'm just going to alter the db and add a simple hook_form_alter for the specific form.

haggins’s picture

The version from #27 is not working properly since maxlength module needs a patch for stripping tags, too. Otherwise it will tell you your text exceeded length. I will post the patch later.

There aren't any problems with broken html since the js doesn't count html-tags. If maxlength produces broken html anyway it gets fixed by html corrector.
I'm using this on a production site since 2 weeks and it's working pretty well so far :)

vrajak@gmail.com’s picture

Haggins I look forward to your patch as I am looking into using this module, and all fixes and features make it better. :)

haggins’s picture

FileSize
2.08 KB
3.1 KB

Here it is.
I propose to review it and make it more stable (e.g. sometimes the first character counts double) to merge the wysiwyg_maxlength module into the maxlength module as an optional submodule.

Patch against 6.x-2.x-dev.

haggins’s picture

Version: 6.x-2.0-beta1 » 6.x-2.x-dev
Category: bug » feature
haggins’s picture

Version: 6.x-2.x-dev » 6.x-2.0-beta1
Category: feature » bug

I'm sorry - I forgot to apply some changes to the tinyMCE plugin. This happened because I'm using only ckeditor. TinyMCE plugin untested!

Also, I created a new issue since this is another one than the original poster had. Please use #1027966: Do not count html markup for further development on this issue.

kiwad’s picture

Title: Doesn't work with tinyMCE » Doesn't work with WYSIWYG (tinyMCE and CKeditor)
Version: 6.x-2.0-beta1 » 6.x-2.x-dev
Status: Needs review » Needs work

Marking #859746: Countdown !remaining not dynamic with CKEditor as a duplicate and changing the title to be more general since haggins' work seems to include both TinyMCE and CKEditor

Also, the files in maxlength as gone through quite a bit of changes (feb 16th), could it be possible to re-roll this to be able to test it with latest dev ?

tseven’s picture

Title: Doesn't work with WYSIWYG (tinyMCE and CKeditor) » Patch against the latest dev
FileSize
3.58 KB

Here is haggins patch from #33 re-worked to work with the dev version (2011-Feb-25).

The sub module:
http://drupal.org/files/issues/wysiwyg_maxlength.tar_.gz
didn't work for me. The js file isn't being loaded.

For a temporary fix, I've just included the fckeditor.js from the wysiwyg_maxlength in my theme.

haggins’s picture

The sub module:
http://drupal.org/files/issues/wysiwyg_maxlength.tar_.gz
didn't work for me. The js file isn't being loaded.

Did you enable the editor plugin at your editors profile?

haggins’s picture

Title: Patch against the latest dev » Doesn't work with WYSIWYG (tinyMCE and CKeditor)

Changing title again to make this issue easier to find.

Anonymous’s picture

This sub-module maybe fix the problem for the wysiwyg module, but I have a CKeditor module.
The #859746: Countdown !remaining not dynamic with CKEditor patch worked well for the previous version, no one can apply it to the new version?

tseven’s picture

I did. Checking the pages source revealed the .js wasn't being included.
I'm using the admin module with the rubik theme,.. that might have something to do with it.

BenK’s picture

Subscribing

held69’s picture

subscribing

Anybody’s picture

@ #37: I can confirm that the module works great in the current Drupal 6.x Version plus the newest Version of tinyMCE.
We use ZEN as Theme, so maybe it's really your Theme causing the incompatibility?

firebus’s picture

the module in #33 did not work for me with

  • maxlength 6.x-2.0-beta2
  • wysiwyg 6.x-2.3
  • ckeditor 3.5.3.6655

ckeditor is generally broken (for example, you can hit the bold button and start writing bold text, but the bold button is not highlighted, and there's no way to turn it off - likewise for other buttons)

also, when switching the editor on and off, maxlength totally breaks and the text is not preserved by wysiwyg

I know that when haggins first posted the module, wysiwyg was at a different revision, and perhaps ckeditor was as well.

the module is working for me with tiny_mce 3.4.7.

fyi, i posted an updated patch to maxlength's strip_html feature in #1027966: Do not count html markup to fix some bugs, make it work with wysiwyg disabled, and update to maxlength 6.x-2.0-beta2

MiSc’s picture

Issue summary: View changes

Need to update wyysiwyg_maxlength, so I uploaded it to a sandbox: https://drupal.org/sandbox/mikkex/2254933
Update of patch coming soon.

MiSc’s picture

Status: Needs work » Needs review
FileSize
4.52 KB

Here is a patch to work with wyysiwyg_maxlength and latest dev of 6.x-2.x.

MiSc’s picture

Updated patch, missing include

cedewey’s picture

Status: Needs review » Closed (won't fix)

The Drupal 6 version of Maxlength is no longer supported so I'm marking this Closed (won't fix).

I also encourage you, if you haven't already, to upgrade your site to Drupal 8/9. We are actively maintaining that version and you would enjoy all of the other features of the latest version of Drupal.