File

projects/ng-dynamic-forms/core/src/lib/model/input/dynamic-input.model.ts

Extends

DynamicInputControlModel

Index

Properties
Methods
Accessors

Constructor

constructor(config: DynamicInputModelConfig, layout?: DynamicFormControlLayout)
Parameters :
Name Type Optional
config DynamicInputModelConfig No
layout DynamicFormControlLayout Yes

Properties

Private _list
Type : any[] | null
Default value : null
Decorators :
@serializable('list')
Private Readonly _listId
Type : string | null
Default value : null
accept
Type : string | null
Decorators :
@serializable()
files
Type : FileList | null
Default value : null
inputType
Type : string
Decorators :
@serializable()
list$
Type : Observable<any[]> | null
Default value : null
mask
Type : string | RegExp | Function | (string | RegExp)[] | null
Decorators :
@serializable()
max
Type : number | string | Date | null
Decorators :
@serializable()
min
Type : number | string | Date | null
Decorators :
@serializable()
multiple
Type : boolean | null
Decorators :
@serializable()
pattern
Type : string | null
Decorators :
@serializable()
step
Type : number | null
Decorators :
@serializable()
Readonly type
Type : string
Default value : DYNAMIC_FORM_CONTROL_TYPE_INPUT
Decorators :
@serializable()
autoComplete
Type : string
Decorators :
@serializable()
Inherited from DynamicInputControlModel
autoFocus
Type : boolean
Decorators :
@serializable()
Inherited from DynamicInputControlModel
maxLength
Type : number | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
minLength
Type : number | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
placeholder
Type : string
Decorators :
@serializable()
Inherited from DynamicInputControlModel
prefix
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
readOnly
Type : boolean
Decorators :
@serializable()
Inherited from DynamicInputControlModel
spellCheck
Type : boolean
Decorators :
@serializable()
Inherited from DynamicInputControlModel
suffix
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Private _value
Type : T | null
Decorators :
@serializable('value')
Inherited from DynamicInputControlModel
additional
Type : literal type | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
hint
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
required
Type : boolean
Decorators :
@serializable()
Inherited from DynamicInputControlModel
tabIndex
Type : number | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Private Readonly value$
Type : BehaviorSubject<T>
Inherited from DynamicInputControlModel
Readonly valueChanges
Type : Observable<T>
Inherited from DynamicInputControlModel
_disabled
Type : boolean
Decorators :
@serializable('disabled')
Inherited from DynamicInputControlModel
asyncValidators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
controlTooltip
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Private Readonly disabled$
Type : BehaviorSubject<boolean>
Inherited from DynamicInputControlModel
Readonly disabledChanges
Type : Observable<boolean>
Inherited from DynamicInputControlModel
errorMessages
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
hidden
Type : boolean
Decorators :
@serializable()
Inherited from DynamicInputControlModel
id
Type : string
Decorators :
@serializable()
Inherited from DynamicInputControlModel
label
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
labelTooltip
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
layout
Type : DynamicFormControlLayout | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
name
Type : string
Decorators :
@serializable()
Inherited from DynamicInputControlModel
parent
Type : DynamicPathable | null
Default value : null
Inherited from DynamicInputControlModel
relations
Type : DynamicFormControlRelation[]
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Abstract Readonly type
Type : string
Inherited from DynamicInputControlModel
updateOn
Type : DynamicFormHook | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
validators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
_disabled
Type : boolean
Decorators :
@serializable('disabled')
Inherited from DynamicInputControlModel
asyncValidators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
controlTooltip
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Private Readonly disabled$
Type : BehaviorSubject<boolean>
Inherited from DynamicInputControlModel
Readonly disabledChanges
Type : Observable<boolean>
Inherited from DynamicInputControlModel
errorMessages
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
hidden
Type : boolean
Decorators :
@serializable()
Inherited from DynamicInputControlModel
id
Type : string
Decorators :
@serializable()
Inherited from DynamicInputControlModel
label
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
labelTooltip
Type : string | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
layout
Type : DynamicFormControlLayout | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
name
Type : string
Decorators :
@serializable()
Inherited from DynamicInputControlModel
parent
Type : DynamicPathable | null
Default value : null
Inherited from DynamicInputControlModel
relations
Type : DynamicFormControlRelation[]
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Abstract Readonly type
Type : string
Inherited from DynamicInputControlModel
updateOn
Type : DynamicFormHook | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
validators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicInputControlModel
Private _value
Type : T | null
Decorators :
@serializable('value')
additional
Type : literal type | null
Decorators :
@serializable()
hint
Type : string | null
Decorators :
@serializable()
required
Type : boolean
Decorators :
@serializable()
tabIndex
Type : number | null
Decorators :
@serializable()
Private Readonly value$
Type : BehaviorSubject<T>
Readonly valueChanges
Type : Observable<T>
_disabled
Type : boolean
Decorators :
@serializable('disabled')
asyncValidators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
controlTooltip
Type : string | null
Decorators :
@serializable()
Private Readonly disabled$
Type : BehaviorSubject<boolean>
Readonly disabledChanges
Type : Observable<boolean>
errorMessages
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
hidden
Type : boolean
Decorators :
@serializable()
id
Type : string
Decorators :
@serializable()
label
Type : string | null
Decorators :
@serializable()
labelTooltip
Type : string | null
Decorators :
@serializable()
layout
Type : DynamicFormControlLayout | null
Decorators :
@serializable()
name
Type : string
Decorators :
@serializable()
parent
Type : DynamicPathable | null
Default value : null
relations
Type : DynamicFormControlRelation[]
Decorators :
@serializable()
Abstract Readonly type
Type : string
updateOn
Type : DynamicFormHook | null
Decorators :
@serializable()
validators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
_disabled
Type : boolean
Decorators :
@serializable('disabled')
Inherited from DynamicFormControlModel
asyncValidators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
controlTooltip
Type : string | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
Private Readonly disabled$
Type : BehaviorSubject<boolean>
Inherited from DynamicFormControlModel
Readonly disabledChanges
Type : Observable<boolean>
Inherited from DynamicFormControlModel
errorMessages
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
hidden
Type : boolean
Decorators :
@serializable()
Inherited from DynamicFormControlModel
id
Type : string
Decorators :
@serializable()
Inherited from DynamicFormControlModel
label
Type : string | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
labelTooltip
Type : string | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
layout
Type : DynamicFormControlLayout | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
name
Type : string
Decorators :
@serializable()
Inherited from DynamicFormControlModel
parent
Type : DynamicPathable | null
Default value : null
Inherited from DynamicFormControlModel
relations
Type : DynamicFormControlRelation[]
Decorators :
@serializable()
Inherited from DynamicFormControlModel
Abstract Readonly type
Type : string
Inherited from DynamicFormControlModel
updateOn
Type : DynamicFormHook | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel
validators
Type : DynamicValidatorsConfig | null
Decorators :
@serializable()
Inherited from DynamicFormControlModel

Methods

toJSON
toJSON()
Returns : any
getAdditional
getAdditional(key: string, defaultValue?: any | null)
Inherited from DynamicInputControlModel
Parameters :
Name Type Optional
key string No
defaultValue any | null Yes
Returns : any
toJSON
toJSON()
Inherited from DynamicInputControlModel
Returns : any
toJSON
toJSON()
Inherited from DynamicInputControlModel
Returns : any
getAdditional
getAdditional(key: string, defaultValue?: any | null)
Parameters :
Name Type Optional
key string No
defaultValue any | null Yes
Returns : any
toJSON
toJSON()
Returns : any
toJSON
toJSON()
Inherited from DynamicFormControlModel
Returns : any

Accessors

listId
getlistId()
hasList
gethasList()
list
setlist(list)
Parameters :
Name Optional
list No
Returns : void
import { DynamicInputControlModel, DynamicInputControlModelConfig } from "../dynamic-input-control.model";
import { DynamicFormControlLayout } from "../misc/dynamic-form-control-layout.model";
import { serializable } from "../../decorator/serializable.decorator";
import { maskToString } from "../../utils/json.utils";
import { isBoolean, isFunction, isNumber } from "../../utils/core.utils";
import { Observable, isObservable, of } from "rxjs";
import { tap } from "rxjs/operators";

export const DYNAMIC_FORM_CONTROL_TYPE_INPUT = "INPUT";

export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_COLOR = "color";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_DATE = "date";
//export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_DATETIME = "datetime";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_DATETIME_LOCAL = "datetime-local";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_EMAIL = "email";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_FILE = "file";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_MONTH = "month";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_NUMBER = "number";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_PASSWORD = "password";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_RANGE = "range";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_SEARCH = "search";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_TEL = "tel";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_TEXT = "text";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_TIME = "time";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_URL = "url";
export const DYNAMIC_FORM_CONTROL_INPUT_TYPE_WEEK = "week";

export interface DynamicInputModelConfig extends DynamicInputControlModelConfig<string | number | Date | string[]> {

    accept?: string;
    inputType?: string;
    list?: any[] | Observable<any[]>;
    mask?: string | RegExp | Function | (string | RegExp)[];
    max?: number | string | Date;
    min?: number | string | Date;
    multiple?: boolean;
    pattern?: string;
    step?: number;
}

export class DynamicInputModel extends DynamicInputControlModel<string | number | Date | string[]> {

    @serializable() accept: string | null;
    @serializable() inputType: string;
    files: FileList | null = null;
    list$: Observable<any[]> | null = null;
    @serializable() mask: string | RegExp | Function | (string | RegExp)[] | null;
    @serializable() max: number | string | Date | null;
    @serializable() min: number | string | Date | null;
    @serializable() multiple: boolean | null;
    @serializable() pattern: string | null;
    @serializable() step: number | null;

    @serializable("list") private _list: any[] | null = null;
    private readonly _listId: string | null = null;

    @serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_INPUT;

    constructor(config: DynamicInputModelConfig, layout?: DynamicFormControlLayout) {

        super(config, layout);

        this.accept = config.accept || null;
        this.inputType = config.inputType || DYNAMIC_FORM_CONTROL_INPUT_TYPE_TEXT;
        this.mask = config.mask || null;
        this.max = config.max !== undefined ? config.max : null;
        this.min = config.min !== undefined ? config.min : null;
        this.multiple = isBoolean(config.multiple) ? config.multiple : null;
        this.pattern = config.pattern || null;
        this.step = isNumber(config.step) ? config.step : null;

        if (config.list !== undefined) {

            this.list = config.list;
            this._listId = `${this.id}List`;
        }
    }

    get listId(): string | null {
        return this._listId;
    }

    get hasList(): boolean {
        return isObservable(this.list$);
    }

    set list(list: any[] | Observable<any[]> | null) {

        if (Array.isArray(list)) {

            this._list = list;
            this.list$ = of(this._list);

        } else if (isObservable(list)) {

            this.list$ = list.pipe(tap(list => this._list = list));

        } else {

            this._list = null;
            this.list$ = null;
        }
    }

    toJSON() {

        const json: any = super.toJSON();

        if (this.mask !== null) {
            json.mask = isFunction(this.mask) ? this.mask : maskToString(this.mask);
        }

        return json;
    }
}

result-matching ""

    No results matching ""