In the previous post I mentioned about manipulating SharePoint PeoplePicker control using JavaScript, in this post I will show how to validate the InputFormTextBox contol using custom JavaScript function. Here is the nice post by Becky Isserman on why not to use RequiredFieldValdator or InputFormRequiredFieldValidator with InputFormTextbox.
function ValidateComments()
{
//retrieve the text from rich text editor.
var text = RTE_GetRichEditTextOnly("<%= rteComments.ClientID %>");
if (text != "")
{
return true;
}
else
{
alert('Please enter your comments.');
//set focus back to the rich text editor.
RTE_GiveEditorFocus("<%= rteComments.ClientID %>");
return false;
}
return true;
}
<SharePoint:InputFormTextBox ID="rteComments" runat="server" RichText="true" RichTextMode="Compatible" Rows="10" TextMode="MultiLine" CausesValidation="true" ></SharePoint:InputFormTextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" OnClientClick="return ValidateComments()" CausesValidation="true" />
- Jignesh