Help us understand the problem. What is going on with this article?

【SharePoint 2013】JSリンクで編集フォームの項目を条件によって読み取り専用にする

More than 1 year has passed since last update.

既定の編集フォームを JSリンクで表示を切り替えるサンプルソースです。
サンプルではフィールドの種類を設定していますが、固有の列名を指定してもOKです。

(function () {
    var ctx = {};
    ctx.Templates = {};
    ctx.Templates.Fields = {
        'Text': {// 1行テキスト
            'EditForm': function (ctx) {
                // 判定処理を書く
                var readOnly = false;
                if (readOnly) {
                    return SPField_FormDisplay_Default(ctx);
                } else {
                    return SPFieldText_Edit(ctx);
                }
            },
        },
        'Note': {// 複数行テキスト
            'EditForm': function (ctx) {
                // 判定処理を書く
                var readOnly = false;
                if (readOnly) {
                    return SPFieldNote_Display(ctx);
                } else {
                    return SPFieldNote_Edit(ctx);
                }
            },
        },
        'User': {// ユーザー
            'EditForm': function (ctx) {
                // 判定処理を書く
                var readOnly = true;
                if (readOnly) {
                    prepareUserFieldValue(ctx);
                    return SPFieldUser_Display(ctx);
                } else {
                    return SPClientPeoplePickerCSRTemplate(ctx);
                }
            },
        },
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();

// コンテンツを正しく表示するには、ユーザーコントロールに特定の書式設定された値が必要です。
function prepareUserFieldValue(ctx) {
    var userFields = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];

    var fieldValue = "";

    for (var i = 0; i < userFields.length; i++) {
        var user = userFields[i];
        fieldValue += user.EntityData.SPUserID;
        fieldValue += SPClientTemplates.Utility.UserLookupDelimitString;
        fieldValue += user.DisplayText;

        if ((i + 1) != userFields.length) {
            fieldValue += SPClientTemplates.Utility.UserLookupDelimitString;
        }
    }

    ctx.CurrentFieldValue = fieldValue;
}

参考サイト

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした