Error - Cannot read properties of undefined (reading 'id') while adding custom file picker property to custom webpart

kem104 170 Reputation points
2024-03-13T14:48:55.7133333+00:00

I am getting following error , while adding the file picker property to my Custom webpart.

First time I am creating custom webpart with file picker property so I get some reference from this site - PropertyFieldFilePicker - @pnp/spfx-property-controls. I did exactly same this which is in that article and getting the error.

Could anyone please help me to find out where I make some mistake? here I also share some code for reference.

anyone help will be appreciated.

User's image

code for reference

User's image

User's image

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,443 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 39,926 Reputation points Microsoft External Staff
    2024-03-14T07:17:13.6966667+00:00

    Hi @kem104,

    You could check the steps to instsall file picker. First run this command to install the controls.

    npm install @pnp/spfx-property-controls
    

    Add this to your main webpart code.

    import
    

    Add a new property to your web part interface props.

    YAMLCopy

    filePickerResult:
    

    Then add into the getPropertyPaneConfiguration() function in your webpart under groupFields.

    PropertyFieldFilePicker('filePicker', {
          context: this.context,
          filePickerResult: this.properties.filePickerResult,
          properties: this.properties,
          onSave: (e: IFilePickerResult) => {
               console.log(e);
               this.properties.filePickerResult = e;
          },
          onChanged: (e: IFilePickerResult) => {
               console.log(e);
               this.properties.filePickerResult = e;
          },
          key: "filePickerId",
          buttonLabel: "File Picker",
          label: "File Picker"
     })
    
    
    

    Please refer to the following document


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.