This is a migrated thread and some comments may be shown as answers.

RadEditor MaxLength Chack On Type adn Paste

1 Answer 16 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Noble
Top achievements
Rank 1
Noble asked on 27 Mar 2014, 01:26 PM
Hi Team,

I am using below function for radetiro maxlength chack on type and paste ,it is working fine for type but not for paste. I am using  getvalue method to get the content of radeditor after paste but this method gives content like (<P><Font>This is the real text</Font></P>) so how can i get the complete text .There is one method gettext() but this method doesnt give complete text of radeditor . I have tried different method getTextarea(),getcontent(),getcontentarea() but end up with no solution. Please provide me solution for that.

function isAlphaNumericKey(keyCode) {
if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91)) {
return true;
}
return false;
}
function LimitCharacters(editor) {
var maxTextLength = editor._maxTextLength;
var messageText = 'Please enter characters less than or equal to ' + editor._maxTextLength + '.';
editor.attachEventHandler("keydown", function (e) {
e = (e == null) ? window.event : e;
if (isAlphaNumericKey(e.keyCode)) {
textLength = editor.get_text().length;
if (textLength >= maxTextLength) {
alert(messageText);
e.returnValue = false;
editor.setFocus();
return false;
}
}
});
}
function CalculateLength(editor, value) {
var textLength = editor.get_text().length;
var clipboardLength = value.length;
textLength += clipboardLength;
return textLength;
}
 
function OnClientPasteHtml(editor, args) {
debugger;
var commandName = args.get_commandName();
var value = args.get_value();
var maxTextLength = editor._maxTextLength;
var messageText = 'Please paste characters less than or equal to ' + editor._maxTextLength + '.';
if (commandName == "PasteFromWord"
|| commandName == "PasteFromWordNoFontsNoSizes"
|| commandName == "PastePlainText"
|| commandName == "PasteAsHtml"
|| commandName == "Paste") {
var textLength = CalculateLength(editor, value);
var textLength2 = editor.get_text().length;
var originalText = editor.get_text() + value;
var requiredLength = maxTextLength - textLength2;
var strippedContent = value.replace(/\<img .+?\>/ig, "");
if (textLength2 == maxTextLength) {
alert(messageText);
var strippedContent = value.replace(/\<img .+?\>/ig, "");
var contentReal = (originalText.substring(0, maxTextLength));
args.set_value(contentReal);
args.set_cancel(true);
}
if (requiredLength != 0) {
var contentReal = (value.substring(0, requiredLength));
args.set_value(contentReal);
}
}
}


Thanks,
Noble Kurian

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 28 Mar 2014, 08:08 AM
Hello Noble,

The paste event cannot retrieve directly stripped content, you should additionally use some method to strip all unwanted tags or another content.

The following example uses the RadEditor's Utils namespace to strip all formatting and leave only the text:
<telerik:RadEditor runat="server" ID="RadEditor1"
     OnClientPasteHtml="OnClientPasteHtml"></telerik:RadEditor>
 
<script type="text/javascript">
    function OnClientPasteHtml(editor, args) {
        var cleanedText = Telerik.Web.UI.Editor.Utils.stripFormatting(args.get_value(), "ALL");
 
        // This code will replace all   entities to ordinary white spaces.
        var replaceWSEntity = cleanedText.replace(/ /gi, " ");
    }
</script>


Regards,
Ianko
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
General Discussions
Asked by
Noble
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or