In our project, we don't want to include the HTML tags and blanks when calculating the length of the content.

Comments

brandy.brown’s picture

I don't think this needs a patch. You can achieve this by enabling the "Truncate HTML" option. Please reopen if necessary.

brandy.brown’s picture

Category: Bug report » Feature request
Issue summary: View changes
Status: Active » Closed (works as designed)
dijithadt’s picture

Issue tags: +maxlength

I already enabled the "Truncate HTML" option in order to exclude html tags in character counting in ckeditor.Still the issue exists and i applied the maxlength-character_count_issue.patch and count getting correct in all cases except for the ul or ol and li tags and for any tags inside the li tag such as strong,bold etc.Customize it to get the correct count in case of ul,ol and li tags and for any tags inside the li tag such as strong,bold etc.

frank.schalkwijk’s picture

Issue summary: View changes
StatusFileSize
new1.83 KB

Recreated patch against 3.2

frank.schalkwijk’s picture

StatusFileSize
new1.62 KB
thomwilhelm’s picture

Had good results using the patch in #4. However I found changing the function htmlspecialchars_decode to html_entity_decode is better as it replaces all HTML entities instead of just a subset of them.

With the existing patch characters like ‘ ’ " are only counted as 1 character in the javascript calculation, but not as 1 character in the maxlength_validate_input function.

markusd1984’s picture

Is this supposed to work also for the ckeditor module (not WYSIWYG module plugin) ?

I tried Force text truncate & Truncate html but didn't help (perhaps they don't apply to the summary inputs).

I tried patching #5 against 7.x-3.x-dev but only /js/maxlength.js seems to have changed.

Hunk #1 FAILED at 235.
1 out of 1 hunk FAILED -- saving rejects to file maxlength.module.rej

I tried manually but the patch but unfortunately it didn't work for me :(

Can you please confirm the changed content is supposed to be:

function maxlength_validate_input(&$element, &$form_state) {
  // Verify that the value is not longer than #maxlength characters.
  if (isset($element['#attributes']['maxlength']) && isset($element['#value'])) {
    // Compute the length of the text, without counting the tags, and consider
    // the "enter" characters as only one character.
// And strip whitespace from the beginning and end of a string
$value = trim(htmlspecialchars_decode(filter_xss(str_replace(array("\r\n", ' '), array('', ' '), $element['#value']), array())));
    $value = strip_tags($value);
    $value = preg_replace("/&#?[a-z0-9]+;/i","1",$value);
    if (drupal_strlen($value) > $element['#attributes']['maxlength']) {
      form_error($element, t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($ele$
    }
    // Giving the element back the #maxlength, maybe some other modules requires it.
    $element['#maxlength'] = $element['#attributes']['maxlength'];
  }
}