Monday, February 15, 2010

Attachment Required Validation for Custom List Form in SharePoint Designer 2007

I have a Custom List Form for Edit Item in a custom aspx page developed using SharePoint Designer. There was a requirement in this. There should be a check for attachments,i.e. attachments should be made mandatory. This had to be achieved through Javascript. The following function helped in achieving the same. Note: This function should be called in the OnSubmit event of the form. Also, don't change the
id "idAttachmentsTable"


function CheckForAttachments()
{
var elm = document.getElementById("idAttachmentsTable");

if (elm == null || elm.rows.length == 0)
{
//document.getElementById("idAttachmentsRow").style.display='none';
alert("Please attach Documents");
return false ;
}
else { return true ;}
}

2 comments:

  1. hi, where to attached the above function??
    I couldnot find on submit event .

    ReplyDelete
  2. Your best bet is to put this in the "function PreSaveAction()" as it's a default function that runs beofre the item saves.

    ReplyDelete