Question

I'm creating a custom field type for Sharepoint using the JSLink method. This field will be used in New List Item / Edit List Item forms.

What I want to do is to allow a user to set a custom property in the list column settings, and then access this property from within the custom field.

Here's what I tried:

1) Using this in the XML file for the field type - this method works for server-side create

 <PropertySchema>
      <Fields>
        <Field Name="MyCustomProperty" DisplayName="This is my custom property" Type="Text" Hidden="False" />
      </Fields>
 </PropertySchema>

2) Using this in the code that initializes the control:

    public MyCustomFieldType(SPFieldCollection fields, string fieldName) :
        base(fields, fieldName)
    {
        this.RichText = true;
        this.RichTextMode = SPRichTextMode.Compatible;
        this.RestrictedMode = false;
        this.UnlimitedLengthInDocumentLibrary = true;
        this.SetCustomProperty("TestProperty", "test1");
        this.ThisIsACustomProperty = "test3";
    }

It seems there is no way I can access those fields from the javascript. Any ideas?

Was it helpful?

Solution

refer msdn

In short, override this method in your C# code, then your custom property will appear in the form context / field schema in javascript.

public override Dictionary<string, object> GetJsonClientFormFieldSchema(Microsoft.SharePoint.WebControls.SPControlMode mode)
        {
            Dictionary<string, object> schema = base.GetJsonClientFormFieldSchema(mode);
            schema.Add("my_displaytemplate", this.DisplayTemplate ?? string.Empty);
            return schema; 
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top