]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
show errors on invalid date input 862/head
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Sun, 1 May 2022 21:03:40 +0000 (14:03 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Sun, 1 May 2022 21:07:31 +0000 (14:07 -0700)
src-ui/src/app/components/document-detail/document-detail.component.html
src-ui/src/app/components/document-detail/document-detail.component.ts

index f9fecdf8544576c5ddd8f57afef0b5533b2a09d5..118f917ec0e091245697834ecf857528e8532c9e 100644 (file)
             <div [ngbNavOutlet]="nav" class="mt-2"></div>
 
             <button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="networkActive || !(isDirty$ | async)">Discard</button>&nbsp;
-            <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive || !(isDirty$ | async)">Save & next</button>&nbsp;
-            <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive || !(isDirty$ | async)">Save</button>&nbsp;
+            <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive || !(isDirty$ | async) || error">Save & next</button>&nbsp;
+            <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive || !(isDirty$ | async) || error">Save</button>&nbsp;
         </form>
     </div>
 
index 05c44045051970fae96e54f54796df38d1aa90bc..9b223f22abde7a71dfed857602b791c4a99f1c5c 100644 (file)
@@ -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() {