From 12a9abeaea1c78ec062d0bb08fce9a2c83f9d04f Mon Sep 17 00:00:00 2001 From: IRRDC Date: Fri, 4 Aug 2023 11:44:54 +0200 Subject: [PATCH 01/14] Bugfix for issue 1568 Dynamic Form accessed TaxonomyFieldTypeMulti without considering sub-array "results". --- src/controls/dynamicForm/DynamicForm.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 86a5a8b70..f93607bc6 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -580,8 +580,8 @@ export class DynamicForm extends React.Component< hiddenName = response.value; termSetId = field.TermSetId; anchorId = field.AnchorId; - if (item !== null) { - item[field.InternalName].forEach((element) => { + if (item !== null && item[field.InternalName] !== null && item[field.InternalName].results !== null) { + item[field.InternalName].results.forEach((element) => { selectedTags.push({ key: element.TermGuid, name: element.Label, From 22b97702d62811058d13c33edf45d4165139e214 Mon Sep 17 00:00:00 2001 From: Guido Date: Mon, 14 Aug 2023 14:48:32 +0200 Subject: [PATCH 02/14] Added file handling in DynamicForm --- .../dynamicForm/DynamicForm.module.scss | 5 + src/controls/dynamicForm/DynamicForm.tsx | 191 ++++++++++++++++-- src/controls/dynamicForm/IDynamicFormProps.ts | 11 + src/controls/dynamicForm/IDynamicFormState.ts | 8 +- src/loc/bg-bg.ts | 3 + src/loc/ca-es.ts | 3 + src/loc/da-dk.ts | 3 + src/loc/de-de.ts | 3 + src/loc/el-gr.ts | 3 + src/loc/en-us.ts | 3 + src/loc/es-es.ts | 3 + src/loc/et-ee.ts | 3 + src/loc/eu-es.ts | 3 + src/loc/fi-fi.ts | 3 + src/loc/fr-ca.ts | 3 + src/loc/fr-fr.ts | 3 + src/loc/it-it.ts | 3 + src/loc/ja-jp.ts | 3 + src/loc/lt-lt.ts | 3 + src/loc/lv-lv.ts | 3 + src/loc/mystrings.d.ts | 3 + src/loc/nb-no.ts | 3 + src/loc/nl-nl.ts | 3 + src/loc/pl-pl.ts | 3 + src/loc/pt-br.ts | 3 + src/loc/pt-pt.ts | 3 + src/loc/ro-ro.ts | 3 + src/loc/ru-ru.ts | 3 + src/loc/sk-sk.ts | 3 + src/loc/sr-latn-rs.ts | 3 + src/loc/sv-se.ts | 3 + src/loc/tr-tr.ts | 3 + src/loc/vi-vn.ts | 3 + src/loc/zh-cn.ts | 3 + src/loc/zh-tw.ts | 3 + 35 files changed, 286 insertions(+), 22 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.module.scss b/src/controls/dynamicForm/DynamicForm.module.scss index 8acbbed6b..51b1a4df7 100644 --- a/src/controls/dynamicForm/DynamicForm.module.scss +++ b/src/controls/dynamicForm/DynamicForm.module.scss @@ -147,3 +147,8 @@ } } } + +.selectedFileContainer { + display: flex; + margin: 10px 0px; +} diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 86a5a8b70..81041ce55 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -12,7 +12,7 @@ import { IStackTokens, Stack } from "office-ui-fabric-react/lib/Stack"; import * as React from "react"; import { IUploadImageResult } from "../../common/SPEntities"; import SPservice from "../../services/SPService"; -import { IFilePickerResult } from "../filePicker"; +import { FilePicker, IFilePickerResult } from "../filePicker"; import { DynamicField } from "./dynamicField"; import { DateFormat, @@ -27,6 +27,7 @@ import { DialogFooter, DialogType, } from "office-ui-fabric-react/lib/Dialog"; +import { Icon } from 'office-ui-fabric-react'; import "@pnp/sp/lists"; import "@pnp/sp/content-types"; @@ -109,6 +110,7 @@ export class DynamicForm extends React.Component< ) : (
+ {this.props.enableFileSelection === true && this.renderFileSelectionControl()} {fieldCollection.map((v, i) => { if ( fieldOverrides && @@ -182,6 +184,9 @@ export class DynamicForm extends React.Component< onSubmitted, onBeforeSubmit, onSubmitError, + enableFileSelection, + validationErrorDialogProps, + returnListItemInstanceOnSubmit } = this.props; try { @@ -213,11 +218,22 @@ export class DynamicForm extends React.Component< } } }); + if (shouldBeReturnBack) { this.setState({ fieldCollection: fields, isValidationErrorDialogOpen: - this.props.validationErrorDialogProps + validationErrorDialogProps + ?.showDialogOnValidationError === true, + }); + return; + } + + if (enableFileSelection === true && this.state.selectedFile === undefined) { + this.setState({ + missingSelectedFile: true, + isValidationErrorDialogOpen: + validationErrorDialogProps ?.showDialogOnValidationError === true, }); return; @@ -316,7 +332,7 @@ export class DynamicForm extends React.Component< if (onSubmitted) { onSubmitted( iur.data, - this.props.returnListItemInstanceOnSubmit !== false + returnListItemInstanceOnSubmit !== false ? iur.item : undefined ); @@ -334,22 +350,27 @@ export class DynamicForm extends React.Component< contentTypeId === "" || !contentTypeId.startsWith("0x0120") ) { - // We are adding a new list item - try { - const iar = await sp.web.lists.getById(listId).items.add(objects); - if (onSubmitted) { - onSubmitted( - iar.data, - this.props.returnListItemInstanceOnSubmit !== false - ? iar.item - : undefined - ); - } - } catch (error) { - if (onSubmitError) { - onSubmitError(objects, error); + if (contentTypeId === undefined || enableFileSelection === true) { + await this.addFileToLibrary(objects); + } + else { + // We are adding a new list item + try { + const iar = await sp.web.lists.getById(listId).items.add(objects); + if (onSubmitted) { + onSubmitted( + iar.data, + returnListItemInstanceOnSubmit !== false + ? iar.item + : undefined + ); + } + } catch (error) { + if (onSubmitError) { + onSubmitError(objects, error); + } + console.log("Error", error); } - console.log("Error", error); } } else if (contentTypeId.startsWith("0x0120")) { // We are adding a folder or a Document Set @@ -397,6 +418,9 @@ export class DynamicForm extends React.Component< } console.log("Error", error); } + } else if (contentTypeId.startsWith("0x01") && enableFileSelection === true) { + // We are adding a folder or a Document Set + await this.addFileToLibrary(objects); } this.setState({ @@ -411,6 +435,66 @@ export class DynamicForm extends React.Component< } }; + private addFileToLibrary = async (objects: {}) => { + const { + selectedFile + } = this.state; + + const { + listId, + listItemId, + contentTypeId, + onSubmitted, + onBeforeSubmit, + onSubmitError, + returnListItemInstanceOnSubmit + } = this.props; + + try { + const idField = "ID"; + const contentTypeIdField = "ContentTypeId"; + + const library = await sp.web.lists.getById(listId); + const itemTitle = + selectedFile !== undefined && selectedFile.fileName !== undefined && selectedFile.fileName !== "" + ? (selectedFile.fileName as string).replace( + /["|*|:|<|>|?|/|\\||]/g, + "_" + ) // Replace not allowed chars in folder name + : ""; // Empty string will be replaced by SPO with Folder Item ID + + const fileCreatedResult = await library.rootFolder.files.add(itemTitle, selectedFile.downloadFileContent(), true); + const fields = await fileCreatedResult.file.listItemAllFields(); + + if (fields[idField]) { + // Read the ID of the just created folder or Document Set + const folderId = fields[idField]; + + // Set the content type ID for the target item + objects[contentTypeIdField] = contentTypeId; + // Update the just created folder or Document Set + const iur = await library.items.getById(folderId).update(objects); + if (onSubmitted) { + onSubmitted( + iur.data, + returnListItemInstanceOnSubmit !== false + ? iur.item + : undefined + ); + } + } else { + throw new Error( + "Unable to read the ID of the just created folder or Document Set" + ); + } + } catch (error) { + if (onSubmitError) { + onSubmitError(objects, error); + } + console.log("Error", error); + } + } + // trigger when the user change any value in the form private onChange = async ( internalName: string, @@ -840,4 +924,75 @@ export class DynamicForm extends React.Component< return errorMessage; }; + + private renderFileSelectionControl = (): React.ReactElement => { + const { + selectedFile, + missingSelectedFile + } = this.state; + + const labelEl = ; + + return
+
+ + {labelEl} +
+ { + if (filePickerResult.length === 1) { + this.setState({ + selectedFile: filePickerResult[0], + missingSelectedFile: false + }); + } + else { + this.setState({ + missingSelectedFile: true + }); + } + }} + required={true} + context={this.props.context} + hideWebSearchTab={true} + hideStockImages={true} + hideLocalMultipleUploadTab={true} + hideLinkUploadTab={true} + hideSiteFilesTab={true} + checkIfFileExists={true} + /> + {selectedFile &&
+ + {selectedFile.fileName} +
} + {missingSelectedFile === true && +
{strings.DynamicFormRequiredFileMessage}
} +
; + } + + private getFileIconFromExtension = (): string => { + const fileExtension = this.state.selectedFile.fileName.split('.').pop(); + switch (fileExtension) { + case 'pdf': + return 'PDF'; + case 'docx': + case 'doc': + return 'WordDocument'; + case 'pptx': + case 'ppt': + return 'PowerPointDocument'; + case 'xlsx': + case 'xls': + return 'ExcelDocument'; + case 'jpg': + case 'jpeg': + case 'png': + case 'gif': + return 'FileImage'; + default: + return 'Document'; + } + } } diff --git a/src/controls/dynamicForm/IDynamicFormProps.ts b/src/controls/dynamicForm/IDynamicFormProps.ts index f62e44196..2b0bdaf94 100644 --- a/src/controls/dynamicForm/IDynamicFormProps.ts +++ b/src/controls/dynamicForm/IDynamicFormProps.ts @@ -82,4 +82,15 @@ export interface IDynamicFormProps { * Specify validation error dialog properties */ validationErrorDialogProps?: IValidationErrorDialogProps; + + /** + * Specify if the form should support the creation of a new list item with a file. Default - false + */ + enableFileSelection?: boolean; + + /** + * Specify the supported file extensions for the file picker. Default - "docx", "doc", "pptx", "ppt", "xlsx", "xls", "pdf" + * Only used when enableFileSelection is true + */ + supportedFileExtensions?: string[]; } diff --git a/src/controls/dynamicForm/IDynamicFormState.ts b/src/controls/dynamicForm/IDynamicFormState.ts index b182c3caa..d86477259 100644 --- a/src/controls/dynamicForm/IDynamicFormState.ts +++ b/src/controls/dynamicForm/IDynamicFormState.ts @@ -1,11 +1,11 @@ - import { IDynamicFieldProps } from './dynamicField/IDynamicFieldProps'; +import { IFilePickerResult } from "../filePicker"; + export interface IDynamicFormState { fieldCollection: IDynamicFieldProps[]; isSaving?: boolean; etag?: string; isValidationErrorDialogOpen: boolean; + selectedFile?: IFilePickerResult; + missingSelectedFile?: boolean; } - - - diff --git a/src/loc/bg-bg.ts b/src/loc/bg-bg.ts index 657246024..d0bdc6223 100644 --- a/src/loc/bg-bg.ts +++ b/src/loc/bg-bg.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Стойността трябва да е по-голяма от {0}", "DynamicFormNumberValueMustBeBetween": "Стойността трябва да е между {0} и {1}", "DynamicFormNumberValueMustBeLowerThan": "Стойността трябва да е по-ниска от {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Използвайте това местоположение:", "ListItemCommentDIalogDeleteSubText": "Наистина ли искате да изтриете този коментар?", "ListItemCommentsDialogDeleteTitle": "Потвърдете Изтриване на коментар", diff --git a/src/loc/ca-es.ts b/src/loc/ca-es.ts index 556f0370f..5645ba1ed 100644 --- a/src/loc/ca-es.ts +++ b/src/loc/ca-es.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "El valor ha de ser superior a {0}", "DynamicFormNumberValueMustBeBetween": "El valor ha d'estar entre {0} i {1}", "DynamicFormNumberValueMustBeLowerThan": "El valor ha de ser inferior a {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Utilitzeu aquesta ubicació:", "ListItemCommentDIalogDeleteSubText": "Esteu segur que voleu suprimir aquest comentari?", "ListItemCommentsDialogDeleteTitle": "Confirmació de la supressió del comentari", diff --git a/src/loc/da-dk.ts b/src/loc/da-dk.ts index 85077d2e1..f47d1c6ea 100644 --- a/src/loc/da-dk.ts +++ b/src/loc/da-dk.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Værdien skal være større end {0}", "DynamicFormNumberValueMustBeBetween": "Værdien skal være mellem {0} og {1}", "DynamicFormNumberValueMustBeLowerThan": "Værdien skal være lavere end {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Brug denne placering:", "ListItemCommentDIalogDeleteSubText": "Er du sikker på, at du vil slette denne kommentar?", "ListItemCommentsDialogDeleteTitle": "Bekræft kommentar til sletning", diff --git a/src/loc/de-de.ts b/src/loc/de-de.ts index e4cadb1ed..9cc0e640a 100644 --- a/src/loc/de-de.ts +++ b/src/loc/de-de.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Der Wert muss größer als {0} sein.", "DynamicFormNumberValueMustBeBetween": "Der Wert muss zwischen {0} und {1} liegen.", "DynamicFormNumberValueMustBeLowerThan": "Der Wert muss niedriger als {0} sein.", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Verwenden Sie diesen Speicherort:", "ListItemCommentDIalogDeleteSubText": "Sind Sie sicher, dass Sie diesen Kommentar löschen möchten?", "ListItemCommentsDialogDeleteTitle": "Kommentar löschen bestätigen", diff --git a/src/loc/el-gr.ts b/src/loc/el-gr.ts index 5768b6d9a..e2602a0c5 100644 --- a/src/loc/el-gr.ts +++ b/src/loc/el-gr.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Η τιμή πρέπει να είναι μεγαλύτερη από {0}", "DynamicFormNumberValueMustBeBetween": "Η τιμή πρέπει να είναι μεταξύ {0} και {1}", "DynamicFormNumberValueMustBeLowerThan": "Η τιμή πρέπει να είναι μικρότερη από {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Χρησιμοποιήστε αυτήν τη θέση:", "ListItemCommentDIalogDeleteSubText": "Είστε βέβαιοι ότι θέλετε να διαγράψετε αυτό το σχόλιο;", "ListItemCommentsDialogDeleteTitle": "Επιβεβαίωση διαγραφής σχολίου", diff --git a/src/loc/en-us.ts b/src/loc/en-us.ts index daeea6c12..1bb5072d8 100644 --- a/src/loc/en-us.ts +++ b/src/loc/en-us.ts @@ -387,6 +387,9 @@ define([], () => { DynamicFormNumberValueMustBeGreaterThan: "Value must be greater than {0}", DynamicFormNumberValueMustBeBetween: "Value must be between {0} and {1}", DynamicFormNumberValueMustBeLowerThan: "Value must be lower than {0}", + DynamicFormChooseFileLabel: "File", + DynamicFormChooseFileButtonText: "Select file", + DynamicFormRequiredFileMessage: "File is required.", customDisplayName: "Use this location:", ListItemCommentDIalogDeleteSubText: "Are you sure that you want to delete this comment?", ListItemCommentsDialogDeleteTitle: "Confirm Delete Comment", diff --git a/src/loc/es-es.ts b/src/loc/es-es.ts index 202970148..5eb162460 100644 --- a/src/loc/es-es.ts +++ b/src/loc/es-es.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "El valor debe ser mayor que {0}", "DynamicFormNumberValueMustBeBetween": "El valor debe estar entre {0} y {1}", "DynamicFormNumberValueMustBeLowerThan": "El valor debe ser inferior a {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Utilice esta ubicación:", "ListItemCommentDIalogDeleteSubText": "¿Está seguro de que desea eliminar este comentario?", "ListItemCommentsDialogDeleteTitle": "Confirmar comentario de eliminación", diff --git a/src/loc/et-ee.ts b/src/loc/et-ee.ts index 050d7fa9e..3e405310a 100644 --- a/src/loc/et-ee.ts +++ b/src/loc/et-ee.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Väärtus peab olema suurem kui {0}", "DynamicFormNumberValueMustBeBetween": "Väärtus peab olema vahemikus {0} kuni {1}", "DynamicFormNumberValueMustBeLowerThan": "Väärtus peab olema väiksem kui {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Kasuta seda asukohta:", "ListItemCommentDIalogDeleteSubText": "Kas soovite kindlasti selle kommentaari kustutada?", "ListItemCommentsDialogDeleteTitle": "Kommentaari kustutamise kinnitamine", diff --git a/src/loc/eu-es.ts b/src/loc/eu-es.ts index fc6b030c8..d39f064b3 100644 --- a/src/loc/eu-es.ts +++ b/src/loc/eu-es.ts @@ -385,5 +385,8 @@ TermSetNavigationNoTerms: "No terms defined", "DynamicFormNumberValueMustBeGreaterThan": "Balioak {0} baino handiagoa izan behar du", "DynamicFormNumberValueMustBeBetween": "Balioak {0} eta {1} artean egon behar du", "DynamicFormNumberValueMustBeLowerThan": "Balioak {0} baino txikiagoa izan behar du", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", }; }); diff --git a/src/loc/fi-fi.ts b/src/loc/fi-fi.ts index daa8b4838..18fc8e38a 100644 --- a/src/loc/fi-fi.ts +++ b/src/loc/fi-fi.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Arvon on oltava suurempi kuin {0}", "DynamicFormNumberValueMustBeBetween": "Tämän kentän arvon on oltava välillä {0} - {1}", "DynamicFormNumberValueMustBeLowerThan": "Arvon on oltava pienempi kuin {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Käytä tätä sijaintia:", "ListItemCommentDIalogDeleteSubText": "Haluatko varmasti poistaa tämän kommentin?", "ListItemCommentsDialogDeleteTitle": "Vahvista poista kommentti", diff --git a/src/loc/fr-ca.ts b/src/loc/fr-ca.ts index ce6cd7273..17e543318 100644 --- a/src/loc/fr-ca.ts +++ b/src/loc/fr-ca.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "La valeur doit être supérieure à {0}", "DynamicFormNumberValueMustBeBetween": "La valeur doit être comprise entre {0} et {1}", "DynamicFormNumberValueMustBeLowerThan": "La valeur doit être inférieure à {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Utilisez cet emplacement :", "ListItemCommentDIalogDeleteSubText": "Êtes-vous sûr de vouloir supprimer ce commentaire?", "ListItemCommentsDialogDeleteTitle": "Confirmer supprimer le commentaire", diff --git a/src/loc/fr-fr.ts b/src/loc/fr-fr.ts index 96b761670..0002353d9 100644 --- a/src/loc/fr-fr.ts +++ b/src/loc/fr-fr.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "La valeur doit être supérieure à {0}", "DynamicFormNumberValueMustBeBetween": "La valeur doit être comprise entre {0} et {1}", "DynamicFormNumberValueMustBeLowerThan": "La valeur doit être inférieure à {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Utilisez cet emplacement :", "ListItemCommentDIalogDeleteSubText": "Êtes-vous sûr de vouloir supprimer ce commentaire ?", "ListItemCommentsDialogDeleteTitle": "Confirmer la suppression du commentaire", diff --git a/src/loc/it-it.ts b/src/loc/it-it.ts index 17e8e53a5..39d159563 100644 --- a/src/loc/it-it.ts +++ b/src/loc/it-it.ts @@ -367,6 +367,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Il valore inserito deve essere maggiore di {0}", "DynamicFormNumberValueMustBeBetween": "Il valore inserito deve essere compreso tra {0} e {1}", "DynamicFormNumberValueMustBeLowerThan": "Il valore inserito deve essere minore di {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Seleziona file", + "DynamicFormRequiredFileMessage": "Il file è obbligatorio.", "customDisplayName": "Utilizzare questa posizione:", "ListItemCommentDIalogDeleteSubText": "Eliminare questo commento?", "ListItemCommentsDialogDeleteTitle": "Conferma eliminazione commento", diff --git a/src/loc/ja-jp.ts b/src/loc/ja-jp.ts index c3f91d841..9aa425cbe 100644 --- a/src/loc/ja-jp.ts +++ b/src/loc/ja-jp.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "値は {0} より大きくなければなりません", "DynamicFormNumberValueMustBeBetween": "値は {0} から {1} の間である必要があります", "DynamicFormNumberValueMustBeLowerThan": "値は {0} より小さい必要があります", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "この場所を使用します。", "ListItemCommentDIalogDeleteSubText": "このコメントを削除しますか?", "ListItemCommentsDialogDeleteTitle": "コメントの削除の確認", diff --git a/src/loc/lt-lt.ts b/src/loc/lt-lt.ts index 30dd26c20..8babf88be 100644 --- a/src/loc/lt-lt.ts +++ b/src/loc/lt-lt.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Reikšmė turi būti didesnė nei {0}", "DynamicFormNumberValueMustBeBetween": "Reikšmė turi būti nuo {0} iki {1}", "DynamicFormNumberValueMustBeLowerThan": "Vertė turi būti mažesnė nei {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Naudokite šią vietą:", "ListItemCommentDIalogDeleteSubText": "Ar tikrai norite panaikinti šį komentarą?", "ListItemCommentsDialogDeleteTitle": "Patvirtinti naikinimo komentarą", diff --git a/src/loc/lv-lv.ts b/src/loc/lv-lv.ts index 99f814d7a..ad05dd058 100644 --- a/src/loc/lv-lv.ts +++ b/src/loc/lv-lv.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Vērtībai ir jābūt lielākai par {0}", "DynamicFormNumberValueMustBeBetween": "Vērtībai ir jābūt no {0} līdz {1}", "DynamicFormNumberValueMustBeLowerThan": "Vērtībai ir jābūt mazākai par {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Izmantojiet šo atrašanās vietu:", "ListItemCommentDIalogDeleteSubText": "Vai tiešām vēlaties dzēst šo komentāru?", "ListItemCommentsDialogDeleteTitle": "Apstiprināt dzēst komentāru", diff --git a/src/loc/mystrings.d.ts b/src/loc/mystrings.d.ts index c390bd064..a74034efc 100644 --- a/src/loc/mystrings.d.ts +++ b/src/loc/mystrings.d.ts @@ -371,6 +371,9 @@ declare interface IControlStrings { DynamicFormNumberValueMustBeGreaterThan: string; DynamicFormNumberValueMustBeBetween: string; DynamicFormNumberValueMustBeLowerThan: string; + DynamicFormChooseFileLabel: string; + DynamicFormChooseFileButtonText: string; + DynamicFormRequiredFileMessage: string; // Location picker customDisplayName: string; diff --git a/src/loc/nb-no.ts b/src/loc/nb-no.ts index 87fcb47a3..3c9d7d8c1 100644 --- a/src/loc/nb-no.ts +++ b/src/loc/nb-no.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Verdien må være større enn {0}", "DynamicFormNumberValueMustBeBetween": "Verdien må være mellom {0} og {1}", "DynamicFormNumberValueMustBeLowerThan": "Verdien må være lavere enn {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Bruk denne plasseringen:", "ListItemCommentDIalogDeleteSubText": "Er du sikker på at du vil slette denne kommentaren?", "ListItemCommentsDialogDeleteTitle": "Bekreft sletting av kommentar", diff --git a/src/loc/nl-nl.ts b/src/loc/nl-nl.ts index d45a67361..a7e7404dd 100644 --- a/src/loc/nl-nl.ts +++ b/src/loc/nl-nl.ts @@ -367,6 +367,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Waarde moet groter zijn dan {0}", "DynamicFormNumberValueMustBeBetween": "Waarde moet tussen {0} en {1} liggen", "DynamicFormNumberValueMustBeLowerThan": "Waarde moet lager zijn dan {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Gebruik deze locatie:", "ListItemCommentDIalogDeleteSubText": "Weet u zeker dat u deze opmerking wilt verwijderen?", "ListItemCommentsDialogDeleteTitle": "Opmerking verwijderen bevestigen", diff --git a/src/loc/pl-pl.ts b/src/loc/pl-pl.ts index 1b9e49f79..56a9abb94 100644 --- a/src/loc/pl-pl.ts +++ b/src/loc/pl-pl.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Wartość musi być większa niż {0}", "DynamicFormNumberValueMustBeBetween": "Wartość musi mieścić się w przedziale od {0} do {1}", "DynamicFormNumberValueMustBeLowerThan": "Wartość musi być mniejsza niż {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Użyj tej lokalizacji:", "ListItemCommentDIalogDeleteSubText": "Czy na pewno chcesz usunąć ten komentarz?", "ListItemCommentsDialogDeleteTitle": "Potwierdź Usuń komentarz", diff --git a/src/loc/pt-br.ts b/src/loc/pt-br.ts index d92259aa1..f828f6ec0 100644 --- a/src/loc/pt-br.ts +++ b/src/loc/pt-br.ts @@ -367,6 +367,9 @@ define([], () => { DynamicFormNumberValueMustBeGreaterThan: "O valor deve ser maior que {0}", DynamicFormNumberValueMustBeBetween: "O valor deve estar entre {0} e {1}", DynamicFormNumberValueMustBeLowerThan: "O valor deve ser inferior a {0}", + DynamicFormChooseFileLabel: "File", + DynamicFormChooseFileButtonText: "Select file", + DynamicFormRequiredFileMessage: "File is required.", customDisplayName: "Utilize este local:", ListItemCommentDIalogDeleteSubText: "Tem a certeza que quer eliminar este comentário?", ListItemCommentsDialogDeleteTitle: "Confirmar Eliminar Comentário", diff --git a/src/loc/pt-pt.ts b/src/loc/pt-pt.ts index f924ce8f7..d6a5f174a 100644 --- a/src/loc/pt-pt.ts +++ b/src/loc/pt-pt.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "O valor deve ser maior que {0}", "DynamicFormNumberValueMustBeBetween": "O valor deve estar entre {0} e {1}", "DynamicFormNumberValueMustBeLowerThan": "O valor deve ser inferior a {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Utilize este local:", "ListItemCommentDIalogDeleteSubText": "Tem a certeza que quer eliminar este comentário?", "ListItemCommentsDialogDeleteTitle": "Confirmar Eliminar Comentário", diff --git a/src/loc/ro-ro.ts b/src/loc/ro-ro.ts index 9ff7cbb43..dba0e7718 100644 --- a/src/loc/ro-ro.ts +++ b/src/loc/ro-ro.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Valoarea trebuie să fie mai mare decât {0}", "DynamicFormNumberValueMustBeBetween": "Valoarea trebuie să fie între {0} și {1}", "DynamicFormNumberValueMustBeLowerThan": "Valoarea trebuie să fie mai mică decât {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Utilizați această locație:", "ListItemCommentDIalogDeleteSubText": "Sunteți sigur că doriți să ștergeți acest comentariu?", "ListItemCommentsDialogDeleteTitle": "Confirmați ștergerea comentariului", diff --git a/src/loc/ru-ru.ts b/src/loc/ru-ru.ts index 3bf9a69c7..621817b45 100644 --- a/src/loc/ru-ru.ts +++ b/src/loc/ru-ru.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Значение должно быть больше {0}", "DynamicFormNumberValueMustBeBetween": "Значение должно быть между {0} и {1}.", "DynamicFormNumberValueMustBeLowerThan": "Значение должно быть меньше {0}.", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Используйте это расположение:", "ListItemCommentDIalogDeleteSubText": "Вы уверены, что хотите удалить этот комментарий?", "ListItemCommentsDialogDeleteTitle": "Подтвердить удаление комментария", diff --git a/src/loc/sk-sk.ts b/src/loc/sk-sk.ts index 7d63fad4c..ca1f71afe 100644 --- a/src/loc/sk-sk.ts +++ b/src/loc/sk-sk.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Hodnota musí byť väčšia ako {0}", "DynamicFormNumberValueMustBeBetween": "Hodnota musí byť medzi {0} a {1}", "DynamicFormNumberValueMustBeLowerThan": "Hodnota musí byť nižšia ako {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Použite toto umiestnenie:", "ListItemCommentDIalogDeleteSubText": "Naozaj chcete odstrániť tento komentár?", "ListItemCommentsDialogDeleteTitle": "Potvrdiť odstránenie komentára", diff --git a/src/loc/sr-latn-rs.ts b/src/loc/sr-latn-rs.ts index 5c08bc58c..9498dc9f3 100644 --- a/src/loc/sr-latn-rs.ts +++ b/src/loc/sr-latn-rs.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Vrednost mora da bude veća od {0}", "DynamicFormNumberValueMustBeBetween": "Vrednost mora da bude između {0} i {1}", "DynamicFormNumberValueMustBeLowerThan": "Vrednost mora biti manja od {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Koristi ovu lokaciju:", "ListItemCommentDIalogDeleteSubText": "Želite li zaista da izbrišete ovaj komentar?", "ListItemCommentsDialogDeleteTitle": "Potvrda brisanja komentara", diff --git a/src/loc/sv-se.ts b/src/loc/sv-se.ts index 9b86d84d6..c6fa28d5f 100644 --- a/src/loc/sv-se.ts +++ b/src/loc/sv-se.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Värdet måste vara större än {0}", "DynamicFormNumberValueMustBeBetween": "Värdet måste vara mellan {0} och {1}", "DynamicFormNumberValueMustBeLowerThan": "Värdet måste vara lägre än {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Använd den här platsen:", "ListItemCommentDIalogDeleteSubText": "Vill du ta bort den här kommentaren?", "ListItemCommentsDialogDeleteTitle": "Bekräfta ta bort kommentar", diff --git a/src/loc/tr-tr.ts b/src/loc/tr-tr.ts index bf40a39ba..b833ce806 100644 --- a/src/loc/tr-tr.ts +++ b/src/loc/tr-tr.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Değer, {0} değerinden büyük olmalıdır", "DynamicFormNumberValueMustBeBetween": "Değer, {0} ile {1} arasında olmalıdır", "DynamicFormNumberValueMustBeLowerThan": "Değer, {0} değerinden düşük olmalıdır", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Bu konumu kullan:", "ListItemCommentDIalogDeleteSubText": "Bu yorumu silmek istediğinizden emin misiniz?", "ListItemCommentsDialogDeleteTitle": "Açıklamayı Sil'i Onayla", diff --git a/src/loc/vi-vn.ts b/src/loc/vi-vn.ts index 2e0688ca7..64faf4a3a 100644 --- a/src/loc/vi-vn.ts +++ b/src/loc/vi-vn.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "Giá trị phải lớn hơn {0}", "DynamicFormNumberValueMustBeBetween": "Giá trị phải nằm trong khoảng từ {0} đến {1}", "DynamicFormNumberValueMustBeLowerThan": "Giá trị phải thấp hơn {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "Sử dụng vị trí này:", "ListItemCommentDIalogDeleteSubText": "Bạn có chắc chắn rằng bạn muốn xóa bình luận này không?", "ListItemCommentsDialogDeleteTitle": "Xác nhận Xóa Chú thích", diff --git a/src/loc/zh-cn.ts b/src/loc/zh-cn.ts index 5d8a3c4ad..169c1c190 100644 --- a/src/loc/zh-cn.ts +++ b/src/loc/zh-cn.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "值必须大于 {0}", "DynamicFormNumberValueMustBeBetween": "值必须介于 {0} 和 {1} 之间", "DynamicFormNumberValueMustBeLowerThan": "值必须小于 {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "使用此位置:", "ListItemCommentDIalogDeleteSubText": "您确定要删除此评论吗?", "ListItemCommentsDialogDeleteTitle": "确认删除注释", diff --git a/src/loc/zh-tw.ts b/src/loc/zh-tw.ts index 9d10f883c..ae293ea60 100644 --- a/src/loc/zh-tw.ts +++ b/src/loc/zh-tw.ts @@ -369,6 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "值必須大於 {0}", "DynamicFormNumberValueMustBeBetween": "值必須介於 {0} 和 {1} 之間", "DynamicFormNumberValueMustBeLowerThan": "值必須小於 {0}", + "DynamicFormChooseFileLabel": "File", + "DynamicFormChooseFileButtonText": "Select file", + "DynamicFormRequiredFileMessage": "File is required.", "customDisplayName": "使用此位置:", "ListItemCommentDIalogDeleteSubText": "您確定要刪除此評論嗎?", "ListItemCommentsDialogDeleteTitle": "確認刪除註釋", From fc48461e7dfacac82d47c9997e8f97c5b5252e00 Mon Sep 17 00:00:00 2001 From: Guido Date: Mon, 14 Aug 2023 16:06:44 +0200 Subject: [PATCH 03/14] Updated pt-pt localization --- src/loc/pt-pt.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/loc/pt-pt.ts b/src/loc/pt-pt.ts index d6a5f174a..f8730f87d 100644 --- a/src/loc/pt-pt.ts +++ b/src/loc/pt-pt.ts @@ -369,9 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "O valor deve ser maior que {0}", "DynamicFormNumberValueMustBeBetween": "O valor deve estar entre {0} e {1}", "DynamicFormNumberValueMustBeLowerThan": "O valor deve ser inferior a {0}", - "DynamicFormChooseFileLabel": "File", - "DynamicFormChooseFileButtonText": "Select file", - "DynamicFormRequiredFileMessage": "File is required.", + "DynamicFormChooseFileLabel": "Ficheiro", + "DynamicFormChooseFileButtonText": "Selecionar ficheiro", + "DynamicFormRequiredFileMessage": "Ficheiro é necessário.", "customDisplayName": "Utilize este local:", "ListItemCommentDIalogDeleteSubText": "Tem a certeza que quer eliminar este comentário?", "ListItemCommentsDialogDeleteTitle": "Confirmar Eliminar Comentário", From ad27c5ce9289762ad03fd0d9c8a3f5448c23ceaf Mon Sep 17 00:00:00 2001 From: Guido Date: Fri, 18 Aug 2023 10:28:17 +0200 Subject: [PATCH 04/14] Changed file upload --- src/controls/dynamicForm/DynamicForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 81041ce55..617fe8206 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -463,7 +463,7 @@ export class DynamicForm extends React.Component< ) // Replace not allowed chars in folder name : ""; // Empty string will be replaced by SPO with Folder Item ID - const fileCreatedResult = await library.rootFolder.files.add(itemTitle, selectedFile.downloadFileContent(), true); + const fileCreatedResult = await library.rootFolder.files.addChunked(encodeURI(itemTitle), await selectedFile.downloadFileContent()); const fields = await fileCreatedResult.file.listItemAllFields(); if (fields[idField]) { From b5425b445f70660f08884329df0954f299f1d0ba Mon Sep 17 00:00:00 2001 From: Guido Date: Fri, 18 Aug 2023 15:49:21 +0200 Subject: [PATCH 05/14] Removed file selection in edit mode --- src/controls/dynamicForm/DynamicForm.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 617fe8206..5484728ee 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -110,7 +110,9 @@ export class DynamicForm extends React.Component<
) : (
- {this.props.enableFileSelection === true && this.renderFileSelectionControl()} + {this.props.enableFileSelection === true && + this.props.listItemId === undefined && + this.renderFileSelectionControl()} {fieldCollection.map((v, i) => { if ( fieldOverrides && From 1d650a5413b50fa221fbc9d6cf731134b3087c7f Mon Sep 17 00:00:00 2001 From: guidozam Date: Tue, 26 Sep 2023 22:45:01 +0200 Subject: [PATCH 06/14] Updated loc files and removed unused props --- src/controls/dynamicForm/DynamicForm.tsx | 4 +--- src/loc/fr-ca.ts | 6 +++--- src/loc/fr-fr.ts | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 5484728ee..175f7c9f4 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -437,17 +437,15 @@ export class DynamicForm extends React.Component< } }; - private addFileToLibrary = async (objects: {}) => { + private addFileToLibrary = async (objects: {}): Promise => { const { selectedFile } = this.state; const { listId, - listItemId, contentTypeId, onSubmitted, - onBeforeSubmit, onSubmitError, returnListItemInstanceOnSubmit } = this.props; diff --git a/src/loc/fr-ca.ts b/src/loc/fr-ca.ts index 17e543318..8b8103023 100644 --- a/src/loc/fr-ca.ts +++ b/src/loc/fr-ca.ts @@ -369,9 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "La valeur doit être supérieure à {0}", "DynamicFormNumberValueMustBeBetween": "La valeur doit être comprise entre {0} et {1}", "DynamicFormNumberValueMustBeLowerThan": "La valeur doit être inférieure à {0}", - "DynamicFormChooseFileLabel": "File", - "DynamicFormChooseFileButtonText": "Select file", - "DynamicFormRequiredFileMessage": "File is required.", + "DynamicFormChooseFileLabel": "Fichier", + "DynamicFormChooseFileButtonText": "Sélectionnez un fichier", + "DynamicFormRequiredFileMessage": "Un fichier est requis.", "customDisplayName": "Utilisez cet emplacement :", "ListItemCommentDIalogDeleteSubText": "Êtes-vous sûr de vouloir supprimer ce commentaire?", "ListItemCommentsDialogDeleteTitle": "Confirmer supprimer le commentaire", diff --git a/src/loc/fr-fr.ts b/src/loc/fr-fr.ts index 0002353d9..f51b7447e 100644 --- a/src/loc/fr-fr.ts +++ b/src/loc/fr-fr.ts @@ -369,9 +369,9 @@ define([], () => { "DynamicFormNumberValueMustBeGreaterThan": "La valeur doit être supérieure à {0}", "DynamicFormNumberValueMustBeBetween": "La valeur doit être comprise entre {0} et {1}", "DynamicFormNumberValueMustBeLowerThan": "La valeur doit être inférieure à {0}", - "DynamicFormChooseFileLabel": "File", - "DynamicFormChooseFileButtonText": "Select file", - "DynamicFormRequiredFileMessage": "File is required.", + "DynamicFormChooseFileLabel": "Fichier", + "DynamicFormChooseFileButtonText": "Sélectionnez un fichier", + "DynamicFormRequiredFileMessage": "Un fichier est requis.", "customDisplayName": "Utilisez cet emplacement :", "ListItemCommentDIalogDeleteSubText": "Êtes-vous sûr de vouloir supprimer ce commentaire ?", "ListItemCommentsDialogDeleteTitle": "Confirmer la suppression du commentaire", From 626c0deb9781207d9cec2bd10f67e459bef55a1e Mon Sep 17 00:00:00 2001 From: guidozam Date: Tue, 26 Sep 2023 23:12:58 +0200 Subject: [PATCH 07/14] Updated IDynamicFormProps --- src/controls/dynamicForm/IDynamicFormProps.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controls/dynamicForm/IDynamicFormProps.ts b/src/controls/dynamicForm/IDynamicFormProps.ts index 2b0bdaf94..9298cde5e 100644 --- a/src/controls/dynamicForm/IDynamicFormProps.ts +++ b/src/controls/dynamicForm/IDynamicFormProps.ts @@ -84,7 +84,8 @@ export interface IDynamicFormProps { validationErrorDialogProps?: IValidationErrorDialogProps; /** - * Specify if the form should support the creation of a new list item with a file. Default - false + * Specify if the form should support the creation of a new list item in a document library attaching a file to it. + * Default - false */ enableFileSelection?: boolean; From d59526d81a10cb56480dd932c155921cc0fba3cb Mon Sep 17 00:00:00 2001 From: guidozam Date: Sun, 22 Oct 2023 10:37:35 +0200 Subject: [PATCH 08/14] Added check for content type --- src/controls/dynamicForm/DynamicForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 606f8192a..61a06eafe 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -112,6 +112,8 @@ export class DynamicForm extends React.Component<
{this.props.enableFileSelection === true && this.props.listItemId === undefined && + this.props.contentTypeId !== undefined && + this.props.contentTypeId.startsWith("0x0101") && this.renderFileSelectionControl()} {fieldCollection.map((v, i) => { if ( @@ -215,7 +217,7 @@ export class DynamicForm extends React.Component< shouldBeReturnBack = true; } else if(val.fieldType === "Number"){ shouldBeReturnBack = this.validateNumberOnSubmit(val); - } + } } else if(val.fieldType === "Number"){ if(val.newValue === null){ val.newValue = val.fieldDefaultValue; @@ -364,7 +366,7 @@ export class DynamicForm extends React.Component< // We are adding a new list item try { const contentTypeIdField = "ContentTypeId"; - //check if item contenttype is passed, then update the object with content type id, else, pass the object + //check if item contenttype is passed, then update the object with content type id, else, pass the object contentTypeId !== undefined && contentTypeId.startsWith("0x01") ? objects[contentTypeIdField] = contentTypeId : objects; const iar = await sp.web.lists.getById(listId).items.add(objects); if (onSubmitted) { @@ -1005,6 +1007,7 @@ export class DynamicForm extends React.Component< default: return 'Document'; } + } private validateNumberOnSubmit = (val:IDynamicFieldProps): boolean => { let shouldBeReturnBack = false; From 4bc9cbc175bd4cdb1f54c6fb8c05b477fe992a94 Mon Sep 17 00:00:00 2001 From: guidozam Date: Sun, 22 Oct 2023 10:41:58 +0200 Subject: [PATCH 09/14] Improved enableFileSelection property description --- src/controls/dynamicForm/IDynamicFormProps.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controls/dynamicForm/IDynamicFormProps.ts b/src/controls/dynamicForm/IDynamicFormProps.ts index 9298cde5e..0c67f558c 100644 --- a/src/controls/dynamicForm/IDynamicFormProps.ts +++ b/src/controls/dynamicForm/IDynamicFormProps.ts @@ -85,6 +85,7 @@ export interface IDynamicFormProps { /** * Specify if the form should support the creation of a new list item in a document library attaching a file to it. + * This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document. * Default - false */ enableFileSelection?: boolean; From 6b61ba195b61e3e6376067c9f299d14bfc63fdf5 Mon Sep 17 00:00:00 2001 From: Guido Zambarda Date: Wed, 1 Nov 2023 12:04:34 +0100 Subject: [PATCH 10/14] Update DynamicForm.md --- docs/documentation/docs/controls/DynamicForm.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/documentation/docs/controls/DynamicForm.md b/docs/documentation/docs/controls/DynamicForm.md index 19954739b..fdbda11bc 100644 --- a/docs/documentation/docs/controls/DynamicForm.md +++ b/docs/documentation/docs/controls/DynamicForm.md @@ -38,6 +38,7 @@ The `DynamicForm` can be configured with the following properties: | contentTypeId | string | no | content type ID | | disabled | boolean | no | Allows form to be disabled. Default value is `false`| | disabledFields | string[] | no | InternalName of fields that should be disabled. Default value is `false`| +| enableFileSelection | boolean | no | Specify if the form should support the creation of a new list item in a document library attaching a file to it. This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document. Default value is `false`| | hiddenFields | string[] | no | InternalName of fields that should be hidden. Default value is `false`| | onListItemLoaded | (listItemData: any) => Promise<void> | no | List item loaded handler. Allows to access list item information after it's loaded.| | onBeforeSubmit | (listItemData: any) => Promise<boolean> | no | Before submit handler. Allows to modify the object to be submitted or cancel the submission. To cancel, return `true`.| @@ -45,6 +46,7 @@ The `DynamicForm` can be configured with the following properties: | onSubmitError | (listItemData: any, error: Error) => void | no | Handler of submission error. | | onCancelled | () => void | no | Handler when form has been cancelled. | | returnListItemInstanceOnSubmit | boolean | no | Specifies if `onSubmitted` event should pass PnPJS list item (`IItem`) as a second parameter. Default - `true` | +| supportedFileExtensions | string[] | no | Specify the supported file extensions for the file picker. Only used when enableFileSelection is `true`. Default value is `["docx", "doc", "pptx", "ppt", "xlsx", "xls", "pdf"]`. | | webAbsoluteUrl | string | no | Absolute Web Url of target site (user requires permissions). | | fieldOverrides | {[columnInternalName: string] : {(fieldProperties: IDynamicFieldProps): React.ReactElement\}} | no | Key value pair for fields you want to override. Key is the internal field name, value is the function to be called for the custom element to render. | | respectEtag | boolean | no | Specifies if the form should respect the ETag of the item. Default - `true` | @@ -56,3 +58,14 @@ The `DynamicForm` can be configured with the following properties: | showDialogOnValidationError | boolean | no | Specifies if the dialog should be shown on validation error. Default - `false` | | customTitle | string | no | Specifies a custom title to be shown in the validation dialog. Default - empty | | customMessage | string | no | Specifies a custom message to be shown in the validation dialog. Default - empty | + +## File selection + +To upload a file when creating a new document in a document library you need to specify: +- enableFileSelection: Set this parameter to true to enable file selection. +- contentTypeId: This parameter specifies the target content type ID of the document you are creating. +- supportedFileExtensions: This parameter is optional and is used to specify the supported file extensions if they are different from the default ones. + +Enabling the file selection will display a new button on top of the form that allow the user to select a file from the recent files, browsing OneDrive or select and upload a file from the computer. + +![DynamicFormWithFileSelection](../assets/DynamicFormWithFileSelection.png) From 7458485b725d54c68ac47e4dadde39151e7a46ea Mon Sep 17 00:00:00 2001 From: Guido Zambarda Date: Wed, 1 Nov 2023 12:06:40 +0100 Subject: [PATCH 11/14] Added DynamicFormWithFileSelection.png --- .../assets/DynamicFormWithFileSelection.png | Bin 0 -> 16481 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/documentation/docs/assets/DynamicFormWithFileSelection.png diff --git a/docs/documentation/docs/assets/DynamicFormWithFileSelection.png b/docs/documentation/docs/assets/DynamicFormWithFileSelection.png new file mode 100644 index 0000000000000000000000000000000000000000..548b28573120121d12508d2db0bd41673a97cb11 GIT binary patch literal 16481 zcmeIZXH-+)we%q%&5ej6huXjX-$rJ?aCblOHq;-nIm zpE`()WgNEL-Wk1SKUm>DxDXiqSoR{YFO?>jMBXZ!IMB$ZB4*`7FO4t;F)$anfiNa1 zv+~pd9eYY(Kfl^~JPT_@;aFr9yw3CeDBP{#QYrXxA>Aji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Vf%`*xqCF6-qq|5z5!5hzA$HXMpujv~J8mPSK=;^G4*U`a#zSwrK0R~RA=KiV8Yq9f9241q9?Go3z(s7EAAFxX?4`8h_*W7ayn>TbLiW zoqYY*;)fe^zP!Liew>y1_G<)az)Pw8ypAKJ|4m-x|2mf5n{sVa7@laa;@ZmugX5j8NgGS}3Vzf Date: Thu, 2 Nov 2023 17:26:06 +0100 Subject: [PATCH 12/14] Update DynamicForm.tsx --- src/controls/dynamicForm/DynamicForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 61a06eafe..bedd13244 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -236,7 +236,7 @@ export class DynamicForm extends React.Component< return; } - if (enableFileSelection === true && this.state.selectedFile === undefined) { + if (enableFileSelection === true && this.state.selectedFile === undefined && this.props.listItemId === undefined)) { this.setState({ missingSelectedFile: true, isValidationErrorDialogOpen: From e36ce35a0df65286507af88af2366d04bf9c194d Mon Sep 17 00:00:00 2001 From: guidozam Date: Mon, 6 Nov 2023 11:10:20 +0100 Subject: [PATCH 13/14] Small fixes --- src/controls/dynamicForm/DynamicForm.tsx | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index bedd13244..1af822d22 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -236,7 +236,7 @@ export class DynamicForm extends React.Component< return; } - if (enableFileSelection === true && this.state.selectedFile === undefined && this.props.listItemId === undefined)) { + if (enableFileSelection === true && this.state.selectedFile === undefined && this.props.listItemId === undefined) { this.setState({ missingSelectedFile: true, isValidationErrorDialogOpen: @@ -356,8 +356,8 @@ export class DynamicForm extends React.Component< else if ( contentTypeId === undefined || contentTypeId === "" || - !contentTypeId.startsWith("0x0120")|| - contentTypeId.startsWith("0x01") + (!contentTypeId.startsWith("0x0120") && + contentTypeId.startsWith("0x01")) ) { if (contentTypeId === undefined || enableFileSelection === true) { await this.addFileToLibrary(objects); @@ -365,18 +365,18 @@ export class DynamicForm extends React.Component< else { // We are adding a new list item try { - const contentTypeIdField = "ContentTypeId"; - //check if item contenttype is passed, then update the object with content type id, else, pass the object - contentTypeId !== undefined && contentTypeId.startsWith("0x01") ? objects[contentTypeIdField] = contentTypeId : objects; - const iar = await sp.web.lists.getById(listId).items.add(objects); - if (onSubmitted) { - onSubmitted( - iar.data, - returnListItemInstanceOnSubmit !== false - ? iar.item - : undefined - ); - } + const contentTypeIdField = "ContentTypeId"; + //check if item contenttype is passed, then update the object with content type id, else, pass the object + contentTypeId !== undefined && contentTypeId.startsWith("0x01") ? objects[contentTypeIdField] = contentTypeId : objects; + const iar = await sp.web.lists.getById(listId).items.add(objects); + if (onSubmitted) { + onSubmitted( + iar.data, + returnListItemInstanceOnSubmit !== false + ? iar.item + : undefined + ); + } } catch (error) { if (onSubmitError) { onSubmitError(objects, error); From 9a1184f34617941d4670b5cb6ac75a78a5dd4ebd Mon Sep 17 00:00:00 2001 From: guidozam Date: Sun, 26 Nov 2023 10:18:42 +0100 Subject: [PATCH 14/14] Updated DynamicForm doc --- .../docs/controls/DynamicForm.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/documentation/docs/controls/DynamicForm.md b/docs/documentation/docs/controls/DynamicForm.md index fdbda11bc..ce2326d4d 100644 --- a/docs/documentation/docs/controls/DynamicForm.md +++ b/docs/documentation/docs/controls/DynamicForm.md @@ -26,6 +26,17 @@ import { DynamicForm } from "@pnp/spfx-controls-react/lib/DynamicForm"; ``` ![DynamicForm](../assets/DynamicForm.png) +## File selection + +To upload a file when creating a new document in a document library you need to specify: +- enableFileSelection: Set this parameter to true to enable file selection. +- contentTypeId: This parameter specifies the target content type ID of the document you are creating. +- supportedFileExtensions: This parameter is optional and is used to specify the supported file extensions if they are different from the default ones. + +Enabling the file selection will display a new button on top of the form that allow the user to select a file from the recent files, browsing OneDrive or select and upload a file from the computer. + +![DynamicFormWithFileSelection](../assets/DynamicFormWithFileSelection.png) + ## Implementation The `DynamicForm` can be configured with the following properties: @@ -58,14 +69,3 @@ The `DynamicForm` can be configured with the following properties: | showDialogOnValidationError | boolean | no | Specifies if the dialog should be shown on validation error. Default - `false` | | customTitle | string | no | Specifies a custom title to be shown in the validation dialog. Default - empty | | customMessage | string | no | Specifies a custom message to be shown in the validation dialog. Default - empty | - -## File selection - -To upload a file when creating a new document in a document library you need to specify: -- enableFileSelection: Set this parameter to true to enable file selection. -- contentTypeId: This parameter specifies the target content type ID of the document you are creating. -- supportedFileExtensions: This parameter is optional and is used to specify the supported file extensions if they are different from the default ones. - -Enabling the file selection will display a new button on top of the form that allow the user to select a file from the recent files, browsing OneDrive or select and upload a file from the computer. - -![DynamicFormWithFileSelection](../assets/DynamicFormWithFileSelection.png)