Posts

Showing posts from June, 2010

Required Field validation using Custom Validation for FCKEditor

//Following are the Html Part of aspx page. <FCKeditorV2:FCKeditor ID="fckeditor_test" runat="server" Height="500px" Width="520px" UseBROnCarriageReturn="true" Visible="true" > </FCKeditorV2:FCKeditor> <asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="validate" ClientValidationFunction="ValidateFCK" ErrorMessage="Pls Enter Some Comments"></asp:CustomValidator> <asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="true" ValidationGroup="validate" /> //Following is the Javascript part   function ValidateFCK(source, args) { var FEditorID = 'ctl00_ContentPlaceHolder1_fckeditor_test'; var text = GetPlainText(FEditorID); if (text.length == 0) { args.IsValid = false; FCKeditorAPI.GetInstance(FEditorID).Focus(); return; } args.

Get Plain Text from FCKEditor in any Browser.

The Following Function will help to get plain text from the FCKEditor in almost any browser. // below is the protyping for trim string. function trimString (str) { str = this != window? this : str; return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); } String.prototype.trim = trimString; //following function will return plain text function GetPlainText(FCKEditorID) { var FEditor = FCKeditorAPI.GetInstance(FCKEditorID); var Result = ""; if (FEditor.EditorDocument.body.textContent || FEditor.EditorDocument.body.textContent=="" ) { //Firefox compitable browser Result = FEditor.EditorDocument.body.textContent.trim(); } else { //IE compitable browser Result = FEditor.EditorDocument.body.innerText.trim(); } return Result; }