editor hidden by display=none, javascript GetDocument is not a function error

  •  10-30-2009, 10:59 PM

    editor hidden by display=none, javascript GetDocument is not a function error

    Hi
     
    I have a page with a Cute Editor that the user hides/shows via javascript (setting the <div style='display:none'> )
    The page must validate on the client side (even when the Editor is hidden) .
     But the line "editor.GetDocument()" fails if the editor is hidden.
    Any workaround ?
    Here's a stripped down version of the page. (It works if you remove the display:none)
     
     <script language="javascript" type="text/javascript">
        <!--
            function maxSizeEdit(source, args) {
                alert('<%= edit.ClientID %>');
                args.IsValid = valCuteEditorLength('<%= edit.ClientID %>', 10, 'My Editor');
            }

            function valCuteEditorLength(id, maxLength, controlToValidateName) {
                var editor = document.getElementById(id);
                var editdoc = editor.GetDocument();
                var editbody = editdoc.body;
                   
                var curLength;
                if (document.all)
                { curLength = editbody.innerText.length; }
                else
                { curLength = editbody.textContent.length; }
                
                if (curLength <= maxLength) {
                    return true;
                }
                else {
                    alert(controlToValidateName + ' exceeded ' + maxLength + ' characters');
                    return false;
                }
            }
        //-->
    </script>
          
        <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="sm"></asp:ScriptManager>
        <div>
            <asp:ValidationSummary runat="server" ID="valSummary" DisplayMode="List" ShowSummary="true" />
            <div style="display:none">
            <CE:Editor runat="server" ID="edit" ShowEditMode="False" ShowHtmlMode="False"
                ShowPreviewMode="False" Text="12456789012345"></CE:Editor>
            </div>    
            <asp:CustomValidator runat="server" ID="valEdit" ValidateEmptyText="true" ControlToValidate="edit" ClientValidationFunction="maxSizeEdit" ErrorMessage="Too Big" Text="*"></asp:CustomValidator>    
            
            <asp:Button runat="server" ID="btnOK" Text="OK" CausesValidation="true"/>
        </div>
        </form> 
     
View Complete Thread