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

В SharePoint 2010 у меня есть CEWP, вставленный на страницу newform.aspx.Если я ввожу код непосредственно в CEWP, он работает нормально.Если я помещу код в библиотеку SiteAssets и укажу относительный путь или полный путь, код не будет работать.

Любая помощь по этому вопросу будет принята с благодарностью.

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

function HideFields() {
    //Enter the fields you would like to hide here.
    fieldsToHide = ["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"];

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

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