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

CustomValidator Not Working with RadEditor

2 Answers 176 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Zed
Top achievements
Rank 1
Zed asked on 31 Dec 2008, 03:14 PM
I have this code
<asp:CustomValidator id="valreqEditComment"
                                                                   ControlToValidate="reEditComment"
                                                                   ClientValidationFunction="TestWordCount"
                                                                   Display="Static"
                                                                   ErrorMessage="A value must be entered for the Comment field!"
                                                                   runat="server"/>

but it never gets here:

function TestWordCount(sender, args)
         {
            alert('hello world');
            if (sender.get_text().search("file://w%7b5/,}") == -1)
            {
               
               
                args.IsValid = false;
            }
            else
             {
                args.IsValid = true;
   

            }
          

2 Answers, 1 is accepted

Sort by
0
Accepted
Tervel
Telerik team
answered on 06 Jan 2009, 10:00 AM
Hi Zed,

Thank you for reporting this. We did some research and we are now able to shed some light on the situation.
As the editor's content area is an IFRAME. The built-in covnenient, easy-to-use ASP.NET Validators mechanism is not able to handle and validate IFRAMEs. We have been able to workaround this limitation by adding a couple of hacks into the editor, so it does work with validators. The following demo demostrates this:
http://demos.telerik.com/aspnet-ajax/Editor/Examples/Validators/DefaultCS.aspx

The approach taken in RadEditor is supposed to fully integrate it with the Validators mechanism. Unfortunately, in the test scenario you provided this is not the case out-of-the-box. Our research showed that the problem is rooted more into the Validators framework than the RadEditor itself.

Upon testing, we verified that the CustomValidator's ClientValidationFunction gets called - as long as there is any content set to the editor! So, for the time being as a temporary workaround to your problem while we do further research and possibly improve on that behavior, my suggestion would be to explicitly set an empty space - &nbsp; as the editor's initial content, e.g.
 <asp:CustomValidator id="valreqEditComment" 
                               ControlToValidate="reEditComment" 
                               ClientValidationFunction="TestWordCount" 
                               Display="Static" 
                               ErrorMessage="A value must be entered for the Comment field!" 
                               runat="server"/> 
                             <telerik:radeditor runat="server" ID="reEditComment"
                                <Content>&nbsp;</Content> 
                             </telerik:radeditor> 

Then all will work fine. On a side note - we needed to modify your validator function as well - because your code expects that the sender is the editor. This is not the case. The sender is in fact the validator itself. Here is your code modified:

    <script> 
    function TestWordCount(sender, args) 
    {       
        //Note that sender is NOT the RadEditor. sender is the <span> of the validator. 
        //The content is contained in the args.Value variable     
        var content = args.Value; 
        if (content.search("file://w%7b5/,}") == -1) 
        {                               
            args.IsValid = false
        } 
        else 
         { 
            args.IsValid = true;    
        } 
    } 
    </script> 

Best regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Zed
Top achievements
Rank 1
answered on 06 Jan 2009, 12:53 PM
I guess I did last week what you suggested because it now works.  I cannot remember what I changed though.  

We just upgraded to Q3.  I am hoping that Q3 and JQuery integration will make JQuery accessible to developers.

Thanks
Tags
Editor
Asked by
Zed
Top achievements
Rank 1
Answers by
Tervel
Telerik team
Zed
Top achievements
Rank 1
Share this question
or