From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 1 May 2022 21:03:40 +0000 (-0700) Subject: show errors on invalid date input X-Git-Tag: v1.8.0-beta.rc1~145^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F862%2Fhead;p=thirdparty%2Fpaperless-ngx.git show errors on invalid date input --- diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index f9fecdf854..118f917ec0 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -162,8 +162,8 @@
  -   -   +   +   diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 05c4404505..9b223f22ab 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -146,18 +146,24 @@ export class DocumentDetailComponent this.documentForm.valueChanges .pipe(takeUntil(this.unsubscribeNotifier)) .subscribe((changes) => { + this.error = null if (this.ogDate) { - let newDate = new Date(normalizeDateStr(changes['created'])) - newDate.setHours( - this.ogDate.getHours(), - this.ogDate.getMinutes(), - this.ogDate.getSeconds(), - this.ogDate.getMilliseconds() - ) - this.documentForm.patchValue( - { created: newDate.toISOString() }, - { emitEvent: false } - ) + try { + let newDate = new Date(normalizeDateStr(changes['created'])) + newDate.setHours( + this.ogDate.getHours(), + this.ogDate.getMinutes(), + this.ogDate.getSeconds(), + this.ogDate.getMilliseconds() + ) + this.documentForm.patchValue( + { created: newDate.toISOString() }, + { emitEvent: false } + ) + } catch (e) { + // catch this before we try to save and simulate an api error + this.error = { created: e.message } + } } Object.assign(this.document, this.documentForm.value) @@ -320,16 +326,17 @@ export class DocumentDetailComponent this.documentsService .get(this.documentId) .pipe(first()) - .subscribe( - (doc) => { + .subscribe({ + next: (doc) => { Object.assign(this.document, doc) this.title = doc.title this.documentForm.patchValue(doc) + this.openDocumentService.setDirty(doc.id, false) }, - (error) => { + error: () => { this.router.navigate(['404']) - } - ) + }, + }) } save() {