0

I have a SP 2010 list and I am looking for an option to hide fields from the new, edit and view forms based of a status of another field. Below is the code i have working so far for the new form but this does not query out the status field. Any Suggestions or help on this would be greatly appreciated.

    <script src="https://code.jquery.com/jquery-latest.min.js"></script><script>

function AddToBodyOnLoad(){
    //Ensure that our function is called last by pushing it again
    _spBodyOnLoadFunctionNames.push("HideFields");
}

function HideFields() {
    //Enter the fields you would like to hide here.
    fieldsToHide = ["Additional Information Required from Applicant", "Administrative Review Completed", "App Fee", "Approval Due Date", "Assigned To Lands Officer", "Completeness Decision", "Completeness Rejection Letter Sent", "Completeness Review Due Date", "Date Lands Officer received", "Date Lands Officer started merit review", "Date Received by Region", "Dispostion Type", "External Referral Required", "External Reviewer", "FNC", "Geomatics Review", "Inspection", "Internal Referral Required", "Internal Reviewer", "Merit Decision", "Merit Upload to ECM complete", "Referral Due Date", "Regional OPD", "Security", "Zone"];

    //Get all SharePoint fields
    var formFieldTitles = $(".ms-formtable td.ms-formlabel h3.ms-standardheader");

    //Iterate over each row in the form
    formFieldTitles.each(function () {

    //Get the text of the field title
    var textToMatch = $(this).text();

    //Get the table row associated with this title
    var currentRow = $(this).closest('tr');

    //Iterate over our list of fields we wish to hide
    for (var i = 0; i < fieldsToHide.length; i++){
        var field = fieldsToHide[i];

        //Match the SharePoint field name to our field name
        if (textToMatch.toLowerCase().replace("*", "").trim() === field.toLowerCase().replace("*", "").trim()){

            //Hide this field
            $(currentRow).hide();    
            }
        }
    });
}

//Add our function to the array of onload functions
_spBodyOnLoadFunctionNames.push("AddToBodyOnLoad");

</script>

Your Answer

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

Browse other questions tagged or ask your own question.