From 2c861fbe7860df95c6101b1cbf079f96bf7b55c4 Mon Sep 17 00:00:00 2001 From: Ryan Schouten Date: Sat, 26 Sep 2020 12:12:39 -0700 Subject: [PATCH 1/2] Fix date handling problems and redirect after edit --- samples/react-list-form/package.json | 4 ++-- .../src/common/services/ListFormService.ts | 22 +++++++++++++----- .../src/webparts/listForm/ListFormWebPart.ts | 23 +++++++++++++++++++ .../components/formFields/DateFormField.tsx | 2 +- .../formFields/SPFieldTaxonomyEdit.tsx | 2 +- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/samples/react-list-form/package.json b/samples/react-list-form/package.json index e64982871..52a6ed74b 100755 --- a/samples/react-list-form/package.json +++ b/samples/react-list-form/package.json @@ -1,6 +1,6 @@ { "name": "react-form-webpart", - "version": "1.0.4", + "version": "1.0.5", "private": true, "engines": { "node": ">=0.10.0" @@ -45,4 +45,4 @@ "gulp": "~3.9.1", "tslint-microsoft-contrib": "5.0.0" } -} +} \ No newline at end of file diff --git a/samples/react-list-form/src/common/services/ListFormService.ts b/samples/react-list-form/src/common/services/ListFormService.ts index 81ffd21e2..0dce40982 100644 --- a/samples/react-list-form/src/common/services/ListFormService.ts +++ b/samples/react-list-form/src/common/services/ListFormService.ts @@ -154,13 +154,14 @@ export class ListFormService implements IListFormService { }, }; const formValues = this.GetFormValues(fieldsSchema, data, originalData); - let createAttachmetns = this.GetAttachmentsCreate(data); - let deleteAttachmetns = this.GetAttachmentsDelete(data, originalData); + let createAttachments = this.GetAttachmentsCreate(data); + let deleteAttachments = this.GetAttachmentsDelete(data, originalData); httpClientOptions.body = JSON.stringify({ bNewDocumentUpdate: false, checkInComment: null, formValues, }); + const endpoint = `${webUrl}/_api/web/GetList(@listUrl)/items(@itemId)/ValidateUpdateListItem()` + `?@listUrl=${encodeURIComponent('\'' + listUrl + '\'')}&@itemId=%27${itemId}%27`; try { @@ -170,12 +171,12 @@ export class ListFormService implements IListFormService { } let responseData = await response.json(); responseData.AttachmentResponse = []; - if (deleteAttachmetns.length > 0) { - let deleteResponse = await this.deleteAttachments(webUrl, listUrl, itemId, deleteAttachmetns); + if (deleteAttachments.length > 0) { + let deleteResponse = await this.deleteAttachments(webUrl, listUrl, itemId, deleteAttachments); responseData.AttachmentResponse.push(deleteResponse); } - if (createAttachmetns.length > 0) { - let createResponse = await this.uploadAttachments(webUrl, listUrl, itemId, createAttachmetns); + if (createAttachments.length > 0) { + let createResponse = await this.uploadAttachments(webUrl, listUrl, itemId, createAttachments); responseData.AttachmentResponse.push(createResponse); } return responseData.d.ValidateUpdateListItem.results; @@ -323,6 +324,15 @@ export class ListFormService implements IListFormService { HasException: false, }; } + else if (field.FieldType === "DateTime") { + let dateValue = data[field.InternalName].split('').map((c) => { return (c.charCodeAt(0) < 127) ? c : ''; }).join(''); + return { + ErrorMessage: null, + FieldName: field.InternalName, + FieldValue: dateValue, + HasException: false, + }; + } else { return { ErrorMessage: null, diff --git a/samples/react-list-form/src/webparts/listForm/ListFormWebPart.ts b/samples/react-list-form/src/webparts/listForm/ListFormWebPart.ts index c8e02e820..097ef6047 100644 --- a/samples/react-list-form/src/webparts/listForm/ListFormWebPart.ts +++ b/samples/react-list-form/src/webparts/listForm/ListFormWebPart.ts @@ -34,6 +34,29 @@ export default class ListFormWebPart extends BaseClientSideWebPart { return super.onInit().then((_) => { this.listService = new ListService(this.context.spHttpClient); + //Polyfill array find + if (!Array.prototype["find"]) { + Array.prototype["find"] = function (predicate) { + if (this == null) { + throw new TypeError('Array.prototype.find called on null or undefined'); + } + if (typeof predicate !== 'function') { + throw new TypeError('predicate must be a function'); + } + var list = Object(this); + var length = list.length >>> 0; + var thisArg = arguments[1]; + var value; + + for (var i = 0; i < length; i++) { + value = list[i]; + if (predicate.call(thisArg, value, i, list)) { + return value; + } + } + return undefined; + }; + } }); } diff --git a/samples/react-list-form/src/webparts/listForm/components/formFields/DateFormField.tsx b/samples/react-list-form/src/webparts/listForm/components/formFields/DateFormField.tsx index 6de4b234a..346e4fe7c 100644 --- a/samples/react-list-form/src/webparts/listForm/components/formFields/DateFormField.tsx +++ b/samples/react-list-form/src/webparts/listForm/components/formFields/DateFormField.tsx @@ -35,7 +35,7 @@ export default class DateFormField extends React.Component = (props) => { initialValues={terms} context={context} onChange={(items) => props.valueChanged(getUpdatedValue(items))} - isTermSetSelectable={false} /> + isTermSetSelectable={false} />; }; function getUpdatedValue(terms) { From 6e2c76bbbd54216d9fd9ddcbfed132afbfb86a4d Mon Sep 17 00:00:00 2001 From: Hugo Bernier Date: Fri, 2 Oct 2020 02:54:22 -0400 Subject: [PATCH 2/2] Fixed version number --- samples/react-directory/README.md | 4 ++-- samples/react-directory/package-lock.json | 2 +- samples/react-directory/package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/react-directory/README.md b/samples/react-directory/README.md index f349bca48..f794fb0fc 100755 --- a/samples/react-directory/README.md +++ b/samples/react-directory/README.md @@ -61,7 +61,7 @@ The web part use PnPjs library, Office-ui-fabric-react components Solution|Author(s) --------|--------- -Directory Web Part|João Mendes +Directory Web Part| João Mendes Directory Web Part| Peter Paul Kirschner ([@petkir_at](https://twitter.com/petkir_at)) Directory Web Part| Sudharsan K ([@sudharsank](https://twitter.com/sudharsank)) @@ -71,7 +71,7 @@ Version|Date|Comments -------|----|-------- 1.0.0|July 29, 2019|Initial release 1.0.1|July 19, 2020|Bugfix and mock-service for workbench (```LivePersonaCard``` not supported in workbench) -2.0.0.0|Sep 18 2020|React hooks, paging, dynamic search props, result alignment using office ui fabric stack. +2.0.0|Sep 18 2020|React hooks, paging, dynamic search props, result alignment using office ui fabric stack. ## Disclaimer diff --git a/samples/react-directory/package-lock.json b/samples/react-directory/package-lock.json index f6e10e63c..214e4bd84 100755 --- a/samples/react-directory/package-lock.json +++ b/samples/react-directory/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-directory", - "version": "1.0.1", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/samples/react-directory/package.json b/samples/react-directory/package.json index 56639b57b..af0f7983f 100755 --- a/samples/react-directory/package.json +++ b/samples/react-directory/package.json @@ -1,6 +1,6 @@ { "name": "react-directory", - "version": "1.0.1", + "version": "2.0.0", "private": true, "main": "lib/index.js", "engines": {