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

Validating Radeditor Content

3 Answers 197 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Erin
Top achievements
Rank 1
Erin asked on 31 Aug 2008, 04:58 PM
Hello, how can I tie the update button for the radeditor's content to a validation function?  I basically want to ensure that the user doesn't put javascript and/or links to external sites so I want to check the html of the content and throw an error message if any of these things are found.  I couldn't find a validation event and validation group for the radeditor....

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 03 Sep 2008, 04:10 PM
Hi Erin,

The RadEditor's RemoveScripts filter automatically strips the SCRIPT tags in the content area.

In addition, you can use the add_submit() method of RadEditor to validate the content. This method is executed when the page is submitted and you can obtain the editor's content with editor.get_html(true) and strip the desired tags and scripts with regular expressions or DOM methods.

You can also use a CustomValidator to validate the content. Here is an example demonstrating how to count and restrict the symbols entered in the content area:

<telerik:RadEditor ID="RadEditor1" runat="server"></telerik:RadEditor>
<asp:CustomValidator runat="server" ID="CustomValidator1" ClientValidationFunction="checkLength">*</asp:CustomValidator> 
<asp:Button ID="button1" Text="Submit" runat="server" /> 
<script type="text/javascript"> 
    var limitNum = 50; 
    var message = 'You are not able to type more than ' + limitNum + ' symbols!'; 
     
    function checkLength(validator, args) 
    { 
        var editor = $find('<%=RadEditor1.ClientID%>');     // get a reference to RadEditor
        var editorText = editor.get_text();     //get the HTML content of the control
        args.IsValid = editorText.length < limitNum; 
    } 
</script>

Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Matt
Top achievements
Rank 1
answered on 21 May 2013, 08:43 PM
I know this post is old but I can't find ANYTHING recent...

I'm just trying a simple test on an ASP.Net custom validator:

alert($find("#<%=RE_ChangeComments.ClientID%>").get_text().length);


And I get:

Error: Unable to get value of the property 'get_text': object is null or undefined

Has things changed that much? I'm using Q1 2013.
0
Rumen
Telerik team
answered on 24 May 2013, 10:02 AM
Hello,

You should get a valid reference to RadEditor's client side object to be able to use the get_text() method.
Try remove the # symbol from the $find function and test again:

alert($find("<%=RE_ChangeComments.ClientID%>").get_text().length);

I also tested the code provided in my earlier reply and it works fine with the latest version.

Best regards,
Rumen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
Erin
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Matt
Top achievements
Rank 1
Share this question
or