]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix some date pasting cases 1370/head
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Sun, 7 Aug 2022 03:49:00 +0000 (20:49 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Sun, 7 Aug 2022 15:44:39 +0000 (08:44 -0700)
src-ui/src/app/components/common/input/date/date.component.ts

index 44e7c75130e9be7bf4751307e8f3ad45a61445cc..1687459101697c29c8471628b8b38fb505200ddf 100644 (file)
@@ -1,8 +1,10 @@
 import { Component, forwardRef, OnInit } from '@angular/core'
 import { NG_VALUE_ACCESSOR } from '@angular/forms'
-import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap'
+import {
+  NgbDateAdapter,
+  NgbDateParserFormatter,
+} from '@ng-bootstrap/ng-bootstrap'
 import { SettingsService } from 'src/app/services/settings.service'
-import { LocalizedDateParserFormatter } from 'src/app/utils/ngb-date-parser-formatter'
 import { AbstractInputComponent } from '../abstract-input'
 
 @Component({
@@ -23,7 +25,8 @@ export class DateComponent
 {
   constructor(
     private settings: SettingsService,
-    private ngbDateParserFormatter: NgbDateParserFormatter
+    private ngbDateParserFormatter: NgbDateParserFormatter,
+    private isoDateAdapter: NgbDateAdapter<string>
   ) {
     super()
   }
@@ -43,9 +46,10 @@ export class DateComponent
       let pastedText = clipboardData.getData('text')
       pastedText = pastedText.replace(/[\sa-z#!$%\^&\*;:{}=\-_`~()]+/g, '')
       const parsedDate = this.ngbDateParserFormatter.parse(pastedText)
-      const formattedDate = this.ngbDateParserFormatter.format(parsedDate)
-      this.writeValue(formattedDate)
-      this.onChange(formattedDate)
+      if (parsedDate) {
+        this.writeValue(this.isoDateAdapter.toModel(parsedDate))
+        this.onChange(this.value)
+      }
     }
   }