Validating the SharePoint InputFormTextBox / RichText Editor using JavaScript

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

posted @ Friday, March 12, 2010 3:06 PM
Print

Comments on this entry:

# re: Validating the SharePoint InputFormTextBox / RichText Editor using JavaScript

Left by ankita at 10/5/2010 3:02 PM
Gravatar
thanks for the article . great help .

# re: Validating the SharePoint InputFormTextBox / RichText Editor using JavaScript

Left by Vinodh at 12/17/2010 11:50 AM
Gravatar
Thank you , was very useful

# re: Validating the SharePoint InputFormTextBox / RichText Editor using JavaScript

Left by Anju at 6/28/2011 1:20 PM
Gravatar
Thanks a lot posting.That saved my day

# re: Validating the SharePoint InputFormTextBox / RichText Editor using JavaScript

Left by Praveen Mandalapu at 2/28/2012 1:17 AM
Gravatar
Thanks alot, saved my day..!

# re: Validating the SharePoint InputFormTextBox / RichText Editor using JavaScript

Left by John Gregory at 10/9/2012 5:56 PM
Gravatar
I tried using this with a custom list edit form with no real success.
At first I replaced the SharePoint:FormField with the SharePoint:InputFormTextBox and implemented the script to bind the control to the SharePoint list
(ie. __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos.....)

When I ran a test, the control appear in the form but the data was not bound.

I then reverted back to the original SharePoint:FormField and tried to bind the validator using the ID of the FormField, however, in SP2010 the ID's are dynamically generated and this would not work.

I would really like to be able to validate this field with the on change or blur events but can't seem to get my hooks into those.

Any Suggestions?

JG

Your comment:



(not displayed)

 
 
 
 
 

Live Comment Preview:

 
«July»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789