Create client side Web part, using React Framework commands given below.

  • Open command prompt
  • md LoadButtonpocwebpart
  • cd LoadButtonpocwebpart
  • yo @microsoft/sharepoint- choose react framework
  • run code . to open Visual studio code

For this demo I have added a text field named WebpartTitle, button named ClickHere and a choicegroup field named ChoiceGroups.

  • Add the Web part custom properties for these fields in manifest.json file.
    1. {
    2. "$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json",
    3. "id": "06cc821c-ca66-480a-aae2-33ae02f9c62f",
    4. "alias": "LoadbuttonpocWebPart",
    5. "componentType": "WebPart",
    6. "version": "0.0.1",
    7. "manifestVersion": 2,
    8. "preconfiguredEntries": [{
    9. "groupId": "06cc821c-ca66-480a-aae2-33ae02f9c62f",
    10. "group": { "default": "Under Development" },
    11. "title": { "default": "loadbuttonpoc" },
    12. "description": { "default": "test loading indicator functionality" },
    13. "officeFabricIconFontName": "Page",
    14. "properties": {
    15. "description": "loadbuttonpoc",
    16. "ClickHere":"java",
    17. "WebpartTitle":"test"
    18. }
    19. }]
    20. }
  • Declare the properties in ts file.
    1. export interface ILoadbuttonpocWebPartProps
    2. {
    3. description: string;
    4. WebpartTitle:string;
    5. ChoiceGroups:string;
    6. }
  • Definitions for the fields are added in the getPropertyPaneConfiguration() method in LoadButtonpocwebpart.ts file.
    1. protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    2. return {
    3. pages: [
    4. {
    5. header: {
    6. description: strings.PropertyPaneDescription
    7. },
    8. groups: [
    9. {
    10. groupName: "Web pane properties",
    11. groupFields: [
    12. PropertyPaneButton('ClickHere',
    13. {
    14. text: "ClickHere",
    15. buttonType: PropertyPaneButtonType.Normal,
    16. onClick: this.ButtonClick.bind(this)
    17. }),
    18. PropertyPaneTextField('WebpartTitle', {
    19. label: "Web part Title"
    20. }),
    21. PropertyPaneChoiceGroup('ChoiceGroups', {
    22. label: 'ChoiceGroups',
    23. options: [
    24. { key: 'dotnet', text: 'dotnet' },
    25. { key: 'sharepoint', text: 'sharepoint' },
    26. { key: 'java', text: 'java' }
    27. ]
    28. }),
    29. ]
    30. }
    31. ]
    32. }
    33. ]
    34. };
    35. }
  • Using onclick attribute in propertypanebutton, we are binding onclick method Buttonclick.
  • We can call Buttonclick method with a parameter or without any parameter.
  • Pass ‘this’ parameter to get the context of the Web part, else use this.buttonlclick().
  • Here, I am setting the Web part title text field with a value called ‘updated’, when a button is clicked, so I am passing the Web part context to the onclick method.
    1. private ButtonClick(oldVal: any): any {
    2. this.properties.WebpartTitle="updated";
    3. return "test"
    4. }
  • In the similar way, when choicegroup field values changes, we can set the Web part title field. For this functionality, we need to add onPropertyFieldChanged.
  • When choicegroups field value changes, the Web part title field is set with the selected value.
    1. protected onPropertyPaneFieldChanged(propertyPath: string, oldValue: any, newValue: any): void {
    2. if (propertyPath === 'ChoiceGroups' && newValue) {
    3. this.properties.WebpartTitle=newValue;
    4. }
    5. }

Deploy and testing

Save the file -> run Gulp serve->add the Web part in workbench.html -> edit the Web part properties.



When click here button is clicked, the Web part title field value changes.

  1. ‘Updated’
  2. this.properties.WebpartTitle=”updated”



When choicegroups field value is selected as ‘dotnet’, same value is populated in the Web part title field.