Skip to content

Commit 99e15fd

Browse files
Be able to use a server relative folder path.
1 parent 5eb14c9 commit 99e15fd

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

docs/documentation/docs/controls/DynamicForm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The `DynamicForm` can be configured with the following properties:
6666
| validationErrorDialogProps | IValidationErrorDialogProps | no | Specifies validation error dialog properties |
6767
| customIcons | { [ columnInternalName: string ]: string } | no | Specifies custom icons for the form. The key of this dictionary is the column internal name, the value is the Fluent UI icon name. |
6868
| storeLastActiveTab | boolean | no | When uploading files: Specifies if last active tab will be stored after the Upload panel has been closed. Note: the value of selected tab is stored in the queryString hash. Default - `true` |
69-
| folderPath | string | no | Library relative folder to create the item in. This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document or Folder. Defaults to the root folder. |
69+
| folderPath | string | no | Server relative or library relative folder to create the item in. This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document or Folder. Defaults to the root folder of the library. |
7070

7171
## Validation Error Dialog Properties `IValidationErrorDialogProps`
7272
| Property | Type | Required | Description |

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,10 +1478,26 @@ export class DynamicForm extends React.Component<
14781478
return 'Document';
14791479
}
14801480
}
1481-
1482-
private getFolderByPath = async (listRelativeFolderPath: string, rootFolder: IFolder): Promise<IFolder> => {
1481+
1482+
/**
1483+
* Returns a pnp/sp folder object based on the folderPath and the library the folder is in.
1484+
* The folderPath can be a server relative path, but should be in the same library.
1485+
* @param folderPath The path to the folder coming from the component properties
1486+
* @param rootFolder The rootFolder object of the library
1487+
* @returns
1488+
*/
1489+
private getFolderByPath = async (folderPath: string, rootFolder: IFolder): Promise<IFolder> => {
14831490
const libraryFolder = await rootFolder();
1484-
const folder = sp.web.getFolderByServerRelativePath(`${libraryFolder.ServerRelativeUrl}/${listRelativeFolderPath}`);
1491+
const normalizedFolderPath = decodeURIComponent(folderPath).toLowerCase().replace(/\/$/, "");
1492+
const serverRelativeLibraryPath = libraryFolder.ServerRelativeUrl.toLowerCase().replace(/\/$/, "");
1493+
1494+
// In case of a server relative path in the same library, return the folder
1495+
if (`${normalizedFolderPath}/`.startsWith(`${serverRelativeLibraryPath}/`)) {
1496+
return sp.web.getFolderByServerRelativePath(normalizedFolderPath);
1497+
}
1498+
1499+
// In other cases, expect a list-relative path and return the folder
1500+
const folder = sp.web.getFolderByServerRelativePath(`${serverRelativeLibraryPath}/${normalizedFolderPath}`);
14851501
return folder;
14861502
};
14871503
}

0 commit comments

Comments
 (0)