Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to create files/folders in subfolder using DynamicForm. Closes #1901 #1903

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

martinlingstuyl
Copy link
Contributor

@martinlingstuyl martinlingstuyl commented Nov 13, 2024

Closes #1901

Q A
Bug fix? [ ]
New feature? [x]
New sample? [ ]
Related issues? Closes #1901

What's in this Pull Request?

In its current state, a dynamic form always creates new items/files/folders in the root folder of a list or library. This is not very handy when using the dynamic form on document libraries. For example as a custom form to create document sets.

This PR adds the ability to create files, folders and document sets in subfolders.

I've added an extra option to do this. So the user has full control over the folder that should be used. In this way it doesn't matter how the form is rendered. A RootFolder querystring parameter may be available that the user can use. (For example in the NewForm of an SPFx FormCustomizer) Or it may not be available. The user is in control of what value he supplies...

The feature does not work for list items. Even if list items can also be created in folders. I've not added that currently as it was a little bit more work that I'm not sure is very relevant.

Testing instructions

To test this feature, you'll need a library where you can create document sets. In TestForm.tsx fill in the contentTypeId, folderPath AND hiddenFields properties as follows:

<DynamicForm
          context={this.props.context}
          contentTypeId='0x0120D52000796BC7FCC8B819488729FB2B77B0E799002B2379630DCCB04D883603B763E843D7'
          listId={this.props.context.list.guid.toString()}
          listItemId={this.props.context.itemId}
          hiddenFields={['FileLeafRef']}
          folderPath='Some subfolder/Some deeper subfolder'
          onListItemLoaded={async (listItemData: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
            console.log(listItemData);
          }} />

For the folderPath option, you can also use a server relative URL. For example when using the RootFolder querystring of an SPFx form customizer. However: it should be a path to the same library, otherwise the code will fail.

FileLeafRef should be excluded in hiddenFields, otherwise the form will not submit. This is supposed to be fixed in #1906.

@martinlingstuyl
Copy link
Contributor Author

@joelfmrodrigues, there it is. Hope its up to the repo standards 😉 We didn't discuss a lot beforehand, so I just took a course that seemed most logical to me. Do let me know if you've got a different opinion!

@joelfmrodrigues
Copy link
Collaborator

@martinlingstuyl could you please resolve the conflicts?

@martinlingstuyl
Copy link
Contributor Author

@joelfmrodrigues, done!

@joelfmrodrigues joelfmrodrigues merged commit edc1fc6 into pnp:dev Nov 27, 2024
1 check passed
@joelfmrodrigues
Copy link
Collaborator

@martinlingstuyl many thanks, this is now merged

@joelfmrodrigues joelfmrodrigues added this to the 3.20.0 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants