mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Use NgbDateParserFormatter
This commit is contained in:
parent
8e2cb6d416
commit
0e0cbe3517
@ -1,6 +1,8 @@
|
|||||||
import { Component, forwardRef, OnInit } from '@angular/core'
|
import { Component, forwardRef, OnInit } from '@angular/core'
|
||||||
import { NG_VALUE_ACCESSOR } from '@angular/forms'
|
import { NG_VALUE_ACCESSOR } from '@angular/forms'
|
||||||
|
import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { SettingsService } from 'src/app/services/settings.service'
|
import { SettingsService } from 'src/app/services/settings.service'
|
||||||
|
import { LocalizedDateParserFormatter } from 'src/app/utils/ngb-date-parser-formatter'
|
||||||
import { AbstractInputComponent } from '../abstract-input'
|
import { AbstractInputComponent } from '../abstract-input'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -19,7 +21,10 @@ export class DateComponent
|
|||||||
extends AbstractInputComponent<string>
|
extends AbstractInputComponent<string>
|
||||||
implements OnInit
|
implements OnInit
|
||||||
{
|
{
|
||||||
constructor(private settings: SettingsService) {
|
constructor(
|
||||||
|
private settings: SettingsService,
|
||||||
|
private ngbDateParserFormatter: NgbDateParserFormatter
|
||||||
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,14 +36,16 @@ export class DateComponent
|
|||||||
placeholder: string
|
placeholder: string
|
||||||
|
|
||||||
onPaste(event: ClipboardEvent) {
|
onPaste(event: ClipboardEvent) {
|
||||||
let clipboardData: DataTransfer =
|
const clipboardData: DataTransfer =
|
||||||
event.clipboardData || window['clipboardData']
|
event.clipboardData || window['clipboardData']
|
||||||
if (clipboardData) {
|
if (clipboardData) {
|
||||||
|
event.preventDefault()
|
||||||
let pastedText = clipboardData.getData('text')
|
let pastedText = clipboardData.getData('text')
|
||||||
pastedText = pastedText.replace(/[\sa-z#!$%\^&\*;:{}=\-_`~()]+/g, '')
|
pastedText = pastedText.replace(/[\sa-z#!$%\^&\*;:{}=\-_`~()]+/g, '')
|
||||||
event.preventDefault()
|
const parsedDate = this.ngbDateParserFormatter.parse(pastedText)
|
||||||
this.value = pastedText
|
const formattedDate = this.ngbDateParserFormatter.format(parsedDate)
|
||||||
this.onChange(pastedText)
|
this.writeValue(formattedDate)
|
||||||
|
this.onChange(formattedDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user