mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-08 15:55:31 +01:00
added some reusable form controls
This commit is contained in:
parent
11af74ba36
commit
b35e1bacd4
14 changed files with 217 additions and 1 deletions
43
src-ui/src/app/components/common/input/abstract-input.ts
Normal file
43
src-ui/src/app/components/common/input/abstract-input.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { Component, Directive, forwardRef, Input, OnInit } from '@angular/core';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
@Directive()
|
||||
export class AbstractInputComponent<T> implements OnInit, ControlValueAccessor {
|
||||
|
||||
constructor() { }
|
||||
|
||||
onChange = (newValue: T) => {};
|
||||
|
||||
onTouched = () => {};
|
||||
|
||||
writeValue(newValue: any): void {
|
||||
this.value = newValue
|
||||
}
|
||||
registerOnChange(fn: any): void {
|
||||
this.onChange = fn;
|
||||
}
|
||||
registerOnTouched(fn: any): void {
|
||||
this.onTouched = fn;
|
||||
}
|
||||
setDisabledState?(isDisabled: boolean): void {
|
||||
this.disabled = isDisabled;
|
||||
}
|
||||
|
||||
@Input()
|
||||
title: string
|
||||
|
||||
@Input()
|
||||
disabled = false;
|
||||
|
||||
value: T
|
||||
|
||||
ngOnInit(): void {
|
||||
this.inputId = uuidv4()
|
||||
}
|
||||
|
||||
inputId: string
|
||||
|
||||
@Input()
|
||||
hint: string
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue