首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >内容编辑器Web部件(CEWP)中的JavaScript逻辑

内容编辑器Web部件(CEWP)中的JavaScript逻辑
EN

Stack Overflow用户
提问于 2019-02-25 08:19:03
回答 1查看 170关注 0票数 0

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

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2019-02-25 13:09:32

如果你试图通过文件标题来隐藏字段(Tr),你可以尝试使用$('nobr:contains("field title")'),不管怎样,对于JavaScript/jQuery脚本,总是使用开发人员工具(F12)调试是很有帮助的。

代码语言:javascript
复制
$('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?forum=sharepointgeneral

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54857928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档