使用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; };
时间: 2024-10-10 08:38:29