SharePoint提交前有效性验证

 

In this article we will see how to implement client side validation in SharePoint list with out using SharePoint designer.

For this follow the below steps

  1. 找到需要有效性验证的页面,如NewForm.aspx或者EditForm.aspx
    在URL后面输入红色部分:(http://mysite/ Lists/job/NewForm.aspx?pageview=shared&toolpaneview=2)可以进入编辑模式.
  2. 添加一个 “content editor web part” 并且修改这个web part,在代码视图中输入
  3. Add the below script
    1.<script language="javascript">
    2.function PreSaveAction()
    3.{
    4.//add your JavaScript code here and return true / false
    5.}
    6.</script>

 

 

如:

<script language="javascript">
function PreSaveAction()
{
//add your JavaScript code here and return true / false
      var elm2 = document.getElementById("idAttachmentsTable");
         if (elm2 == null || elm2.rows.length == 0)
{
                    alert('Please attach file!');
             return false;
}
                else
{
                    return true;  
}
}
</script>

 以上代码的作用为:在提交的时候验证附件是否为空,如果空,提示必须添加附件。

另外还可以通过http://www.codeplex.com/SPJsLib杜总发布的JS方案来检测。

posted @ 2010-05-06 11:49  邑尘  阅读(230)  评论(0编辑  收藏  举报