Friday, April 13, 2012

Validation before Save in New or Edit form



If you want to do validation based on other column in your out of the box New or Edit form, you can do it using JQuery in SharePoint 2010.

In the code below I am trying to validate a text column if the value in the status drop down list is ‘In Process’.

The function PreSaveAction() gets fired when the user clicks on ‘Save’ button in the New or Edit form. In this function you can create object of the drop down list and text control and check if the text control is empty when the status is ‘In Process’.

function PreSaveAction()
{
   var selectedVal = $("select[title='Status']").find('option:selected').text();
   if(selectedVal == 'In Process')
   {
       var chrgtoNum = $("input[title='SID Number']").val();
       if(chrgtoNum == '')
       {
          alert('Please enter SID Number.');
          return false;
       }
       else{return true;}
   }
   else {return true;}
}


You can see my other blog to learn how to put this code in New and Edit form.
Validation or control form from JQuery - Default New and Edit forms


Happy SharePointing...

-Vighnesh

No comments: