Логика JavaScript в веб-части редактора контента (CEWP) - PullRequest
0 голосов
/ 25 февраля 2019

Я пытаюсь скрыть поля в форме редактирования на основе условий (значений в других полях) в списке SharePoint.Приведенный ниже код работает, чтобы скрыть поля, но логика сейчас не работает.Используя оповещение, я могу видеть различные значения, выбранные в поле, но условные операторы не сбрасывают 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>

1 Ответ

0 голосов
/ 25 февраля 2019

Если вы пытаетесь скрыть поле (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?forum=sharepointgeneral

...