0

我尝试根据 SharePoint 列表中的条件(其他字段中的值)隐藏编辑表单中的字段。下面的代码用于隐藏字段,但逻辑现在不起作用。使用 alert 我可以看到在该字段中选择的不同值,但条件语句没有像我预期的那样将 fldList 重置为空。对此的任何帮助将不胜感激。我是 JS 新手。

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

function HideFields() {
    //Enter the fields you would like to hide here.
    fieldsToHide = fldList;

    //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();    
            }
        }
    });
}

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

$(document).ready(function () {
    var value = $("select[title='Activity Type Required Field'] option:selected").text();

    if (value = 'New'){
        fldList = ["Additional Information Required from Applicant", "Assigned To (Field)", "Date Lands Officer received", "Date Lands Officer started merit review", "External Referral Required", "External Reviewer", "Inspection", "Internal Referral Required", "Internal Reviewer", "Merit Recommendation by Field", "Merit Upload to ECM complete", "Referral Due Date", "Zone", "FNC", "Merit Decision Letter", "Review Merit Recommendation by PAS", "Security"];
    }
    else if (value = 'Renewal'){
        fldList = [];
    }
    else{
        fldList = [];
    }

});

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

1 回答 1

0

如果您尝试通过归档标题隐藏字段(tr),您可以尝试使用$('nobr:contains("field title")'),无论如何,对于 JavaScript/jQuery 脚本,始终通过开发人员工具(F12)进行调试很有帮助。

$('nobr:contains("field title")').closest('tr').hide();

这是我在 SharePoint 2013 中的示例代码的一个类似线程。

https://social.technet.microsoft.com/Forums/office/en-US/d14766f1-d085-48c3-9efc-16e46ca64bc5/hide-a-field-based-on-the-value-from-another-field?论坛=sharepointgeneral

于 2019-02-25T05:09:31.640 回答