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

URGENT: RAD Editor,how to prevent pasting certain formattings.

1 Answer 144 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Sachidananda
Top achievements
Rank 1
Sachidananda asked on 29 Aug 2011, 04:31 PM
Hi,

Assume end user is trying to copy content from MS word and pasting into rad editor.

When he Right clicks and choose From MS word or use Ctrl+V , how to prevent him from copying

1.Any inserted files or any other objects from MS Word.
2.Tables in MS Word
3.Forecolor/backcolor information
4.Any hyperlinks

But he should be able to copy
1.Text with Fonts specific to what can be chosen from the RAD editor dropdown.
2.Text with Font size specific to what can be chosen from the RAD editor dropdown.
3.Normal formatting like Bold/Italic/Underline,alignment,bulleting etc.

Please help with this as this is very urgent.

Thank you.



1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Aug 2011, 03:42 PM
Hi Sachidananda,

RadEditor does not offer the requested stripping functionality out-of-the box and for the time being we do not plan to provide such.

What you can do is to attach to the OnClientPasteHtml event of RadEditor, obtain the pasted content, strip the unwanted tags and formatting and insert the modified content in the content area:

<script type="text/javascript">
function OnClientPasteHtml(sender, args) {
var commandName = args.get_commandName();
  var value = args.get_value();
  if (commandName == "Paste")
  {
     alert(value);
     //add below regular expressions that will strip the undesired tags, attributes, etc
     value = value.replace(/\<p[^\>]*>/gi, "<br/>").replace(/\<\/p>/gi, "");
      alert(value);
     args.set_value(value); //set the modified pasted content in the editor
  }
}
</script>
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientPasteHtml="OnClientPasteHtml">
<content></content>
</telerik:RadEditor>


All the best,
Rumen
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Editor
Asked by
Sachidananda
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or