Wednesday, 11 April 2012

Requiredfield validation on people picker

here are the few steps required for people picker validation in sharepoint.

1)press F12 and highlight the textarea of the people picker and copy the id
2)dont use (document.getElementById('<%= peoplepickerid.ClientID %>');) ,it wont work
3) then  create a javascript function


function callPostBack() {
       
        var a = document.getElementById('<%= ApprovingAuthorityPicker.ClientID %>'); //wont work

        var b=document.getElementById("ctl00_m_g_efabbd0f_b6f5_492c_92f8_18063b505623_ctl00_ApprovingAuthorityPicker_downlevelTextBox");
        if (b.value != "")
            return true;
        else
        {
        alert("Required field");
            return false;
    }

4)"ctl00_m_g_efabbd0f_b6f5_492c_92f8_18063b505623_ctl00_ApprovingAuthorityPicker_downlevelTextBox" is the copied id from step 1

5)call the javascript function on button click i,e

 <asp:Button ID="btnTopicSubmit" runat="server" Text="Save" OnClick="btnTopicSubmit_Click"  ValidationGroup="g2"
                                                CssClass="nav_newsmall" OnClientClick="return callPostBack();" />

6)check again and enjoy.

Thanks


No comments:

Post a Comment