Wednesday, 31 January 2018

SharePoint Framework Property Controls

Developers have started use of SharePoint framework for developing the client side web parts in SharePoint online(Office 365). Some of the code block is getting repeated across multiple client side web parts like selecting the list, date time selection, color picker, term set picker. Developers have noticed this to the PNP community. Hence Microsoft came up with reusable controls which are similar to our ASP.net concept of user controls. This controls can be added to the web part easily and can be used as custom property in property pane. I didn't find all steps in single blog so decided to summaries here starting from creating the client side web parts.



Step 3 : Install the following dependency to your project

Make sure that node.js command prompt is running and it is referring to your project. Execute the below command.
npm install @pnp/spfx-property-controls --save --save-exact
 Step 4 : Update the configuration file of your project

Go to Config folder, under that open config.json file and add the following line to the localizedresource property.
"PropertyControlStrings": "./node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
"localizedResources": {
    "CustomucwebpartWebPartStrings""lib/webparts/customucwebpart/loc/{locale}.js",
    "PropertyControlStrings""./node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
  }
Step 5 : Adding control to your web part

There are around 6 controls currently available.


  1. PropertyFieldColorPicker
  2. PropertyFieldDateTimePicker
  3. PropertyFieldListPicker
  4. PropertyFieldPeoplePicker
  5. PropertyFieldSpinButton
  6. PropertyFieldTermPicker
we will use PropertyFieldColorPicker control. Import the following module to your web part file.

import { 
  PropertyFieldColorPicker
  PropertyFieldColorPickerStyle 
from '@pnp/spfx-property-controls/lib/PropertyFieldColorPicker';

Add the new property in web part name it color of type string
export interface ICustomucwebpartWebPartProps {
  descriptionstring;
  colorstring
}

Add the custom property control to the group fields of the web part property configuration.
 PropertyFieldColorPicker('color', {
                  label: 'Color',
                  selectedColor: this.properties.color,
                  onPropertyChange: this.onPropertyPaneFieldChanged,
                  properties: this.properties,
                  disabled: false,
                  alphaSliderHidden: false,
                  style: PropertyFieldColorPickerStyle.Full,
                  iconName: 'Precipitation',
                  key: 'colorFieldId'
                })   
To test the web part, display the property value in Render method.
 <p class="${ styles.description }">${escape(this.properties.color)}</p>      
Now run the gulp serve to test property locally.

Add the web part on workbench page then click on edit and in property pane you will see the color property with color picker option available. You can select the color and same value will be displayed in the web part body.






Enjoy coding !!!
Reference:
  1. SharePoint framework property control

9 comments:

  1. Hey Piyush, Its really great information. Thank you for sharing it.

    ReplyDelete
  2. This post is very simple to read and appreciate without leaving any details out. Great work! best places to invest in property

    ReplyDelete
  3. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!! areas to invest in property uk

    ReplyDelete
  4. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! Sobha windsor reviews

    ReplyDelete
  5. I have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information. Gibraltar estate agency

    ReplyDelete
  6. I am definitely enjoying your website. You definitely have some great insight and great stories. palm hills compound

    ReplyDelete
  7. very interesting post.this is my first time visit here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post! https://property-developer-cambodia.blogspot.com/2021/09/must-read-before-making-best-property.html

    ReplyDelete
  8. Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. check this out

    ReplyDelete
  9. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! Marcia Backstrom

    ReplyDelete

Migration issues for SAP.Connector.dll from Win 2003 to Win 2019 server

Recently I got task of migration of asmx web services from windows 2003 to windows 2019 server. These web services fetch data from SAP us...