使用PreSaveAction函数实现客户端自定义验证。
例:【项目编号】为空时,必须填写【责任者】项。(其中【项目编号】为单行文本框,【责任者】为用户/组选择框。)
function PreSaveAction(){ var porjectNo = $("[id$=TextField][Title=‘项目编号‘]").val(); var peoplePickerDiv = $("[id$=‘ClientPeoplePicker‘][title=‘责任者‘]"); peoplePickerDiv.next(".ms-formvalidation").remove(); if (porjectNo == "") { var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id]; if (spPeoplePicker.IsEmpty()) { var errorHtml = ‘<span class="ms-formvalidation sp-peoplepicker-errorMsg"><span role="alert">项目编号为空时,请填写【责任者】。<br></span></span>‘; peoplePickerDiv.after(errorHtml); return false; } } return true; };
【SharePoint】SharePoint 2013 使用PreSaveAction自定义客户端验证
原文:http://www.cnblogs.com/Ryukaka/p/4645966.html