regarding max. message length

Started by klumy, December 28, 2004, 09:49:45 AM

Previous topic - Next topic

klumy

If your message is too long there is a message

The message exceeds the maximum allowed length (20000 characters).

would be nice if SMF also display the current number of characters, so the user knows how many characters he have to delete until he can post his message

A.M.A

in Post.template.php look for:
<textarea class="editor" name="', $context['post_box_name'], '" rows="', $context['post_box_rows'], '" cols="', $context['post_box_columns'], '" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="2"', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? ' style="border: 1px solid red;"' : '', '>', $message, '</textarea>
add after:
    <br />
<span id="signatureLeft"></span>
<script language="JavaScript" type="text/javascript"><!--
function setInnerHTML(element, toValue)
{
if (typeof(element.innerHTML) != "undefined")
   element.innerHTML = toValue;
else
{
var range = document.createRange();
range.selectNodeContents(element);
range.deleteContents();
element.appendChild(range.createContextualFragment(toValue));
}
}
function tick()
{
if (typeof(document.postmodify) != "undefined")
calcCharLeft();
setTimeout("tick()", 1000);
}
function calcCharLeft()
{
var maxLength = ', $modSettings['max_messageLength'],';
var oldSignature = "", currentSignature = document.postmodify.', $context['post_box_name'], '.value;
if (!document.getElementById("signatureLeft"))
return;
if (oldSignature != currentSignature)
{
oldSignature = currentSignature;
if (currentSignature.replace(/\r/, "").length > maxLength)
document.postmodify.', $context['post_box_name'], '.value = currentSignature.replace(/\r/, "").substring(0, maxLength);
currentSignature = document.postmodify.', $context['post_box_name'], '.value.replace(/\r/, "");
}
setInnerHTML(document.getElementById("signatureLeft"), maxLength - currentSignature.length);
}
setTimeout("tick()", 1000);
// --></script>

This will place a counter beneath the post box with the amount of charters left.
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

codenaught

Thank's AMA. I tried it and it works well. Nice job.  ;)
Dev Consultant
Former SMF Doc Coordinator

klumy

great thanks, hopefully this will be a default feature ;)

Advertisement: