EmptyText just like radTextBox

3 posts, 0 answers
  1. Gabriel Beauchamp
    Gabriel Beauchamp avatar
    41 posts
    Member since:
    Jan 2008

    Posted 12 Mar 2008 Link to this post

    Hello,

        Is there a way to put an EmptyText with the Editor, just like the radTextBox? So that when the user clicks on the editor the text disappears, but re-appear once the user clicks elsewhere if nothing was entered.

    Thanks,
  2. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 13 Mar 2008 Link to this post

    Hi Gabriel,

    You can achieve your scenario with the following two events and code below:

    <script type="text/javascript">
    var defaultContent = "Type Text...";
    function OnClientLoad(editor, args)
    {
        editor.set_html(defaultContent);
        $telerik.addExternalHandler(editor.get_document().body, "click", function(e)
        {
            if (editor.get_html(true).trim() == defaultContent)
            {
                editor.set_html("");
            }
        });
        $telerik.addExternalHandler(editor.get_document().body, "blur", function(e)
        {
            if (editor.get_html(true).trim() == "")
            {
                editor.set_html(defaultContent);
            }
        });
    }
    </script>
    <telerik:radeditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1"></telerik:radeditor>

    I hope this helps.

    Kind regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gabriel Beauchamp
    Gabriel Beauchamp avatar
    41 posts
    Member since:
    Jan 2008

    Posted 13 Mar 2008 Link to this post

    Works great in IE, but not in Firefox.

    I did a slight modification to your code and it now works for both Firefox and IE.

    <script type="text/javascript">
    var defaultContent = "Type Text...";
    function OnClientLoad(editor, args)
    {
        editor.set_html(defaultContent);
        var EditorElement = document.all ? editor.get_document().body : editor.get_document();
        $telerik.addExternalHandler(
    EditorElement, "click", function(e)
        {
            if (editor.get_html(true).trim() == defaultContent)
            {
                editor.set_html("");
            }
        });
        $telerik.addExternalHandler(
    EditorElement, "blur", function(e)
        {
            if (editor.get_html(true).trim() == "")
            {
                editor.set_html(defaultContent);
            }
        });
    }
    </script>
    <telerik:radeditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1"></telerik:radeditor>



    Thanks,
     
Back to Top