From 2c861fbe7860df95c6101b1cbf079f96bf7b55c4 Mon Sep 17 00:00:00 2001 From: Ryan Schouten Date: Sat, 26 Sep 2020 12:12:39 -0700 Subject: [PATCH] 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) {