Hello All,
I'm using Prometheus Rad Editor on my page. I set the rad editor to accept only the a limited number of html contents.
I used the following code to accomplish this scenario.
var maxTextLength;
var messageText;
function CharactersLimit(editor)
{
maxTextLength = document.getElementById('<%= hdnColumn.ClientID %>').value == 'Notes'? 1000 : 2800;
messageText = "You have reached the field limit. You cannot type further than " + maxTextLength + " characters.";
editor.AttachEventHandler ("onkeydown", function (e)
{
e = (e == null)? window.event : e;
textLength = editor.get_Html().length;
if (textLength >= maxTextLength)
{
alert(messageText);
e.returnValue = false;
return false;
}
});
Telerik.Web.DomElement.addExternalHandler(editor.get_document().body, "beforepaste",
function(e)
{
var textLength = CalculateLength(editor);
if (textLength >= maxTextLength)
{
alert(messageText);
e.cancelBubble = true;
e.returnValue = false;
return false;
}
});
}
function OnClientCommandExecuting(editor, commandName, oTool)
{
var CmdName = commandName.get_CommandName();
if (CmdName == "PasteFromWord"
|| CmdName == "PasteFromWordNoFontsNoSizes"
|| CmdName == "PastePlainText"
|| CmdName == "PasteAsHtml"
|| CmdName == "Paste")
{
if (document.all)
{
var textLength = CalculateLength (editor);
if (textLength >= maxTextLength)
{
alert(messageText);
return false;
}
}
}
}
//To calculate the length of the Editor text
function CalculateLength(editor)
{
var textLength = editor.get_Html().length;
var clipboardLength = window.clipboardData.getData("Text").length;
textLength += clipboardLength;
return textLength;
}
Its working fine during the keydown event but not during the paste event.
I'm getting the alert message if the character limit has exceeded on both the events, but still my contents from the clipboard is getting pasted.
I'm using Prometheus Rad Editor on my page. I set the rad editor to accept only the a limited number of html contents.
I used the following code to accomplish this scenario.
var maxTextLength;
var messageText;
function CharactersLimit(editor)
{
maxTextLength = document.getElementById('<%= hdnColumn.ClientID %>').value == 'Notes'? 1000 : 2800;
messageText = "You have reached the field limit. You cannot type further than " + maxTextLength + " characters.";
editor.AttachEventHandler ("onkeydown", function (e)
{
e = (e == null)? window.event : e;
textLength = editor.get_Html().length;
if (textLength >= maxTextLength)
{
alert(messageText);
e.returnValue = false;
return false;
}
});
Telerik.Web.DomElement.addExternalHandler(editor.get_document().body, "beforepaste",
function(e)
{
var textLength = CalculateLength(editor);
if (textLength >= maxTextLength)
{
alert(messageText);
e.cancelBubble = true;
e.returnValue = false;
return false;
}
});
}
function OnClientCommandExecuting(editor, commandName, oTool)
{
var CmdName = commandName.get_CommandName();
if (CmdName == "PasteFromWord"
|| CmdName == "PasteFromWordNoFontsNoSizes"
|| CmdName == "PastePlainText"
|| CmdName == "PasteAsHtml"
|| CmdName == "Paste")
{
if (document.all)
{
var textLength = CalculateLength (editor);
if (textLength >= maxTextLength)
{
alert(messageText);
return false;
}
}
}
}
//To calculate the length of the Editor text
function CalculateLength(editor)
{
var textLength = editor.get_Html().length;
var clipboardLength = window.clipboardData.getData("Text").length;
textLength += clipboardLength;
return textLength;
}
Its working fine during the keydown event but not during the paste event.
I'm getting the alert message if the character limit has exceeded on both the events, but still my contents from the clipboard is getting pasted.