Visual Studioでは、リストの新しいフォームにJSLinkを適用する方法

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/82960

  •  10-12-2019
  •  | 
  •  

質問

コンテンツタイプと言う「部署」と「すべての部門」というリストに適用すると、JSリンクを適用したいコンテンツタイプに1つのフィールドがあります。

私は、フィールドをJSリンクを使って異なる方法でレンダリングするためのソリューションが見つかりましたが、それらの記事では、フィールドのプロパティを指定することをお勧めします。

しかし、私はフィールドを単一の形式の新しいフォームにのみレンダリングしたいのです。フィールドが参照されている他のコンテンツタイプでは、通常のレンダリングが必要です。

私は何をすべきか?

役に立ちましたか?

解決

You should do this steps (for example):

Create New Field

<Field ID="{FFCDA660-279E-4581-B451-49365B002B1A}"
     Name="RequestStatus"
     DisplayName="Request status"
     Type="Choice"
     Required="TRUE"
     Overwrite="TRUE">
<CHOICES>
  <CHOICE>Open</CHOICE>
  <CHOICE>In Progress</CHOICE>
  <CHOICE>Resolved</CHOICE>
  <CHOICE>Closed</CHOICE>
  <CHOICE>Reopened</CHOICE>
</CHOICES>
<Default>Open</Default>

Create new content type

  <ContentType ID="0x0100F1541A19429846C599622A6F63255D65"
               Name="Base Request Content Type"
               Overwrite="TRUE"
               Inherits="TRUE">
    <FieldRefs>
      <FieldRef ID="{FFCDA660-279E-4581-B451-49365B002B1A}" Name="RequestStatus" Required="TRUE"/>
    </FieldRefs>
  </ContentType>

Customize your list schema. Set JSLink attribute on the Form tags.

    <List xmlns:ows="Microsoft SharePoint"
      Title="Requests"
      DisableGridEditing="TRUE"
      FolderCreation="FALSE"
      NavigateForFormsPages="FALSE"
      EnableContentTypes="TRUE"
      Direction="$Resources:Direction;"
      Url="Lists/Requests"
      BaseType="0"
      xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
            //Cointent types
    </ContentTypes>
    <Fields>
            //Fileds
    </Fields>
    <Views>
            //Views
    </Views>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" JSLink="~site/Lists/Files/RequestFormCRS.js" />
    </Forms>
  </MetaData>
</List>

Js File sample

(function () {
    if (typeof SPClientTemplates === 'undefined')
        return;
    var fldCtx = {};
    fldCtx.Templates = {};
    fldCtx.Templates.Fields = {
        'RequestStatus': { 'NewForm': renderRequestStatus }
    };

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

function renderRequestStatus(ctx) {
    var formCtx = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    // logic for render html
    var controlHtml = "<input/>";

    formCtx.registerGetValueCallback(formCtx.fieldName, function () {
    // get value logic
       var controlCurrentValue = "my value"; // extract value from control
       return controlCurrentValue;
    });

    return controlHtml;
}

他のヒント

I guess one solution, not super good though, would be to add JSLink to the field. Then in the JSLink file you make a check on for example List name or URL of the current context (ctx).

It would allow you to change rendering only on the specific list.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top