0

I have a SharePoint 2010 list with Drop Down column named "A" which has 3 choice values.

The list has 3 more columns namely "B","C" and "D".

I'm trying to set a validation on the list as below:

  • When choice 1 is selected in Column "A",columns "B","C" and "D" can be blank.

  • When choice 2 is selected in Column "A",column "B" should be made mandatory.

  • When choice 3 is selected in Column "A",columns "C" and "D" should be made mandatory.

I'm not able to make my formula work for more than 1 choice.Below is the formula I have:

=IF([A]="Choice 1",IF(OR([B],[C],[D]="",TRUE,FALSE),TRUE))
  • I'm not sure if it fits to your use case but you could think about using different content types instead of your column A and for each content type you could define your columns B, C and D to be mandatory or optional – DarkTomate Sep 22 '16 at 9:13
  • Is J query an option we could consider? – mohd tahir Sep 22 '16 at 10:07
  • @mohd tahir yes i can consider jquery also.can u help me with the jquery? – George Sep 22 '16 at 16:28
  • @George Please check the answer I have given below. – mohd tahir Sep 23 '16 at 6:48
2

The below Validation formula worked for me:

=IF(AND(ISBLANK([B])=TRUE,[A]="Choice 2"),FALSE,IF(AND(ISBLANK([C])=TRUE,[A]="Choice 3"),FALSE,IF(AND(ISBLANK([D])=TRUE,[A]="Choice 3"),FALSE,TRUE)))
0
  1. Please add a Script editor webpart to your 'New Item' Page.

  2. Add refrences for JQuery and Sptility on the top.

  3. Add below code on your page:

Heres your code:

<script language="javascript" src="../SiteAssets/Jquery.min.js" type="text/javascript"></script>
<script language="javascript" src="../SiteAssets/sputility.min.js" type="text/javascript"></script>
<script>

function PreSaveAction() {
var fieldA = SPUtility.GetSPField('A').GetValue();
var fieldB = SPUtility.GetSPField('B').GetValue();
var fieldC = SPUtility.GetSPField('C').GetValue();
var fieldD = SPUtility.GetSPField('D').GetValue();
if(fieldA=='Choice #1')
{
return true;
}
else if(fieldA=='Choice #2')
{
if(fieldB=='')
{
alert('Please enter value in column B');
return false;
}
else
{
return true;
}
}
else if(fieldA=='Choice #3')
{
if(fieldC=='' || fieldD=='')
{
if(fieldC==''&& fieldD=='')
{
alert('Please enter values in column C and D');
return false;
}
else if(fieldC=='')
{
alert('Please enter value in column C');
return false;
}
else if(fieldD=='')
{
alert('Please enter value in column D');
return false;
}
}
else
{
return true;
}
}

}
</script>

If you need more help let me know please. If you find my answer helpful, please mark it as answered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.