0

I am trying to use js to hide SharePoint Document Library columns based on conditions. Using SP 2010.

I was able to hide drop-down columns based on an initial dro-down column value thanks to a former post: Hide/Show field on list form based on value from another field

However, I am struggling to hide a choice column based on a previous multi-select choice column.

Condition: If multi-select check box option Functional is checked, show next drop-down choice column titled "Functional". If the check-box Functional is not checked, hide the drop-down choice column "Functional".

The below works successfully for hiding a drop-down based on a former drop-down ( hide unless "Send Email" choice column = Leaders/SME). (Ignore the extra script in the snippet, by error)

enter image description here enter image description here

<script src="…/Site%20Assets/jquery.min.js"></script>
<script src="…/Site%20Assets/SPUtilityjs.js"></script> 

<script>

$(document).ready(function ()

{ // Get a the choice field

var choiceField = SPUtility.GetSPField('Send Email?');

// Hide the target fields in form load

SPUtility.GetSPField('Functional').Hide();

// create a function to show or hide a field based on the selected choice Field value

var ShowHideField = function() {

var selectedFieldValue = choiceField.GetValue();

// Hide the 'Functional' field if the selected value is not 'Leaders'

if(selectedFieldValue != 'Leaders/SME') {

SPUtility.GetSPField('Functional').Hide(); }

else { SPUtility.GetSPField('Functional').Show(); } };

// attach the function to choice field

$(choiceField.Dropdown).on('change', ShowHideField); });

The below does NOT work to hide a drop-down if a former Multi-select choice column doesn't have "Functional" option checked:

![enter image description here

<script src="…/Site%20Assets/jquery.min.js"></script>

<script src="…/Site%20Assets/SPUtilityjs.js"></script> 

<script>

$(document).ready(function ()

{ // Get a the choice field

var choiceField = SPUtility.GetSPField('Leaders/SME');

// Hide the target fields in form load

SPUtility.GetSPField('Functional').Hide();

// create a function to show or hide a field based on the selected choice Field value

var ShowHideField = function() {

var selectedFieldValue = choiceField.GetValue();

// Hide the 'Functional' field if the selected value is not 'Functional'

if(selectedFieldValue != 'Functional') {

SPUtility.GetSPField('Functional').Hide(); }

else { SPUtility.GetSPField('Functional').Show(); } };

// attach the function to choice field

$(choiceField.Checkbox).on('change', ShowHideField); });



</script>
0

Solved! By my wonderfully generous colleague.

<script src="...(your SP site)/jquery.min.js"></script>

<script src="...(your SP site)/SPUtilityjs.js"></script>



<script>

$(document).ready(function (){


// Hide all the choice fields



SPUtility.GetSPField('Command').Hide();

SPUtility.GetSPField('Leaders/SME').Hide();

SPUtility.GetSPField('Functional').Hide();



// Get value of send mail option



var choiceField = SPUtility.GetSPField('Send Email?');



var ShowHideField = function() {

               var selectedFieldValue = choiceField.GetValue();



               // Based on choosen send mail? option hide/show appropriate fields



               switch(selectedFieldValue){



                       case("Command"):

                               SPUtility.GetSPField('Command').Show();

                               SPUtility.GetSPField('Leaders/SME').Hide();

                               SPUtility.GetSPField('Functional').Hide();

                       break;



                       case("Leaders/SME"):

                               SPUtility.GetSPField('Leaders/SME').Show();

                               SPUtility.GetSPField('Command').Hide();

                               SPUtility.GetSPField('Functional').Hide();

                       break;



                       case("N/A - Do not send email"):

                               SPUtility.GetSPField('Leaders/SME').Hide();

                              SPUtility.GetSPField('Command').Hide();

                              SPUtility.GetSPField('Functional').Hide();

               }



}



// This function hides the Function  field based on the function checkbox value



var toogleFunction = function(){

        var functionalCB = SPUtility.GetSPField('Leaders/SME').GetValue();

        if(functionalCB != ""){

               SPUtility.GetSPField('Functional').Show();   

               }

        else

        {

               SPUtility.GetSPField('Functional').Hide();

        }             

}      





$(choiceField.Dropdown).on('change', ShowHideField);

$("span[title='Functional']").on('change', toogleFunction);





});



</script>
| improve this answer | |

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.