Validating SharePoint People Picker Using JavaScript
<SharePoint:PeopleEditor ID="pplContarctEmp" runat="server" Visible="false" Height="21px"
Width="200px" MultiSelect="false" ValidatorEnabled="true" EnableBrowse="true"
AllowEmpty="false" />
<asp:CustomValidator ID="CustomValidator1" ClientValidationFunction="CheckReportsTo1"
runat="server" ControlToValidate="" Display="Dynamic" ValidationGroup="gr1" ErrorMessage="Please select Kaizen Owner"
ForeColor="Red" ValidateEmptyText="True"></asp:CustomValidator>
function CheckReportsTo1(source, arguments) {
//// debugger;
if (aspnetForm.ctl00$PlaceHolderMain$ddlCopperKaizens.value == "Contract Employees") {
if (aspnetForm.ctl00_PlaceHolderMain_pplContarctEmp_downlevelTextBox.value == "")
arguments.IsValid = false;
else
arguments.IsValid = true;
}
}
pplpicker4.Controls.Clear();------> Used to clear the peoplepikker control (it means that clearing the user in people pikker)
validation message fire when user cliks in submit button
Change with PeoplePicker ID By Using Inspactelement......
<script type="text/javascript" language="javascript">
function CheckReportsTo(source, arguments) {
if (aspnetForm.ctl00_PlaceHolderMain_pplEHOD_downlevelTextBox.value == "")
arguments.IsValid = false;
else
arguments.IsValid = true;
}
</script>
ctl00_PlaceHolderMain_pplEHOD----> By clicking on people editor "inspect Elemt" their you can find the people picker Id copy it and replace
downlevelTextBox-------> It should be as it is copy paste...
<SharePoint:PeopleEditor ID="pplEHOD" runat="server" Height="21px" Width="200px"
ValidatorEnabled="true" MultiSelect="false" EnableBrowse="true" AllowEmpty="false" />
<asp:CustomValidator ID="CustomValidator8" ClientValidationFunction="CheckReportsTo"
runat="server" ControlToValidate="" Display="Dynamic" ValidationGroup="gr1" ErrorMessage="Please select My HOD"
ForeColor="Red" ValidateEmptyText="True"></asp:CustomValidator>
if (pplContarctEmp.ResolvedEntities.Count > 0)
{
lblKaizenOwnerEmployeeNoValue.Text = GetApprovers(pplContarctEmp);
}
private string GetApprovers(PeopleEditor ppl)
{
foreach (PickerEntity entity in ppl.ResolvedEntities)
{
login = entity.DisplayText.ToString();//Description.ToString();
}
return login;
}
Comments