当前位置:编程学习 > JAVA >>

Use the PreSaveAction for Moss 2010

[javascript]
<script type="text/javascript" language="javascript"> 
function getTagFromIdentifierAndTitle(tagName, identifier, title) { 
  var len = identifier.length; 
  var tags = document.getElementsByTagName(tagName); 
  for (var i=0; i < tags.length; i++) { 
    var tempString = tags[i].id; 
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) { 
      return tags[i]; 
    } 
  } 
  return null; 

 
function PreSaveAction() { 
    var theInputMLTRR = getTagFromIdentifierAndTitle("TextArea","TextField","ColumnName"); 
    var descLength = theInputMLTRR.value.length; 
    var maxLength = 1500; 
    if (descLength > maxLength) 
    { 
        alert("The description field exceeds the " + maxLength + " character limit by " + (descLength - maxLength) + " characters."); 
        return false; 
    } 
    var elm = document.getElementById("idAttachmentsTable"); 
    if (elm == null || elm.rows.length == 0) 
    { 
        document.getElementById("idAttachmentsRow").style.display='none'; 
 
        alert("Please attach a photo"); 
        return false ; 
    } 
    if(null != elm && elm.rows.length > 1) 
    { 
        alert("Only 1 attachment is allowed. Please remove any additional attachments.") 
        return false; 
    } 
    var attachment;  
    var filename="";  
    var validFileExtensions = [".jpg", ".jpeg", ".gif", ".png"]; 
    try {  
        attachment = elm.getElementsByTagName("span")[0].firstChild;  
        filename = attachment.data;  
    }  
    catch (e) { }  
 
    var validExt = false; 
    if(filename != null && filename.length > 0) 
    { 
        for (var j = 0; j < validFileExtensions.length; j++) { 
            var curExtension = validFileExtensions[j]; 
            if (filename.substr(filename.length - curExtension.length, curExtension.length).toLowerCase() == curExtension.toLowerCase()) { 
                validExt = true; 
                break; 
            } 
        } 
        if (!validExt) { 
            alert("The attached file " + filename + " is invalid, allowed extensions are: " + validFileExtensions.join(", ")); 
            return false; 
        } 
    } 
     
    return true; 

</script> 

If the function PreSaveAction return false, then the item form will not be submitted and keep on the creating or updating form.

if the function PreSaveAction return true, then the item will be submitted.

We usually use put the code under this node of New form and update form aspx files :

[html] view plaincopy
<span style="font-size:18px;"><asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server"></span> 

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,