2022-03-11 10:53:32 -08:00
|
|
|
import { Component, forwardRef, OnInit } from '@angular/core'
|
|
|
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms'
|
|
|
|
|
import { SettingsService } from 'src/app/services/settings.service'
|
|
|
|
|
import { AbstractInputComponent } from '../abstract-input'
|
2021-02-24 18:00:26 +01:00
|
|
|
|
|
|
|
|
@Component({
|
2022-03-11 10:53:32 -08:00
|
|
|
providers: [
|
|
|
|
|
{
|
|
|
|
|
provide: NG_VALUE_ACCESSOR,
|
|
|
|
|
useExisting: forwardRef(() => DateComponent),
|
|
|
|
|
multi: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-02-24 18:00:26 +01:00
|
|
|
selector: 'app-input-date',
|
|
|
|
|
templateUrl: './date.component.html',
|
2022-03-11 10:53:32 -08:00
|
|
|
styleUrls: ['./date.component.scss'],
|
2021-02-24 18:00:26 +01:00
|
|
|
})
|
2022-03-11 10:53:32 -08:00
|
|
|
export class DateComponent
|
|
|
|
|
extends AbstractInputComponent<string>
|
|
|
|
|
implements OnInit
|
|
|
|
|
{
|
2021-02-24 18:00:26 +01:00
|
|
|
constructor(private settings: SettingsService) {
|
|
|
|
|
super()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
super.ngOnInit()
|
|
|
|
|
this.placeholder = this.settings.getLocalizedDateInputFormat()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
placeholder: string
|
|
|
|
|
|
2022-03-11 00:11:59 -08:00
|
|
|
// prevent chars other than numbers and separators
|
|
|
|
|
onKeyPress(event: KeyboardEvent) {
|
2022-03-11 08:11:35 -08:00
|
|
|
if ('Enter' !== event.key && !/[0-9,\.\/-]+/.test(event.key)) {
|
2022-03-11 01:03:43 -08:00
|
|
|
event.preventDefault()
|
2022-03-11 00:11:59 -08:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-24 18:00:26 +01:00
|
|
|
}
|