简体   繁体   English

如何在PreSaveAction中实现多个SharePoint表单验证

[英]How do I Implement Multiple SharePoint Form Validations in PreSaveAction

So first, I know nothing about Javascript other than what I find on the web. 所以首先,除了我在网络上找到的东西以外,我对Java语言一无所知。

I have a SharePoint form and I'm trying to implement specific validations when a user presses "Save." 我有一个SharePoint表单,当用户按下“保存”时,我试图实现特定的验证。

These are: 这些是:

  1. Two specific fields of the form can't be the same value. 表单的两个特定字段不能具有相同的值。
  2. The dropdown list value (which is a lookup column) cannot say "Select from list" which is the default option. 下拉列表值(这是一个查找列)不能说“从列表中选择”是默认选项。

There's already a PreSaveAction that prevents it from being saved if there are no documents attached, which works perfectly. 如果没有附加文档,已经有一个PreSaveAction可以防止保存它,这很好用。

However, when I try to add one of the additional validations (again based on what I find on the web) under the PreSaveAction , none of them work. 但是,当我尝试在PreSaveAction下添加其他验证之一(再次基于我在网络上找到的验证)时,它们都不起作用。

I have the form element names, but can't seem to get it to work. 我有表单元素名称,但似乎无法正常使用。

Edit based on comment: The latest code I tried is: 根据评论进行编辑:我尝试过的最新代码是:

<script type="text/javascript" language="javascript">

function PreSaveAction() {
if (document.getElementById('idAttachmentsRow').style.display=='none' )
 {
 alert('Please attach supporting documents.');
 return false ;
}
else {  return true;  }
}

   {
     if($("select[title='Vendor & Co Code'] option:selected").val() == '~Select Vendor from List')
     {
        alert("Please select vendor.")
        return false;
     }
    else
    {
    return true;
    }

  }

The document attachment part works on it own, but when I added the later, neither worked. 文档附件部分可以单独工作,但是当我添加后面的部分时,两者都不起作用。

Your function is not not correct. 您的功能不正确。

Try script below. 请尝试以下脚本。

<script type="text/javascript">
        function PreSaveAction() {
            if (document.getElementById('idAttachmentsRow').style.display=='none' )
            {
                alert('Please attach supporting documents.');
                return false ;
            }
            if ($("select[title='Vendor & Co Code'] option:selected").val() == '~Select Vendor from List') {
                alert("Please select vendor.")
                return false;
            }
            else {
                return true;
            }
        }
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM