File

projects/ng-dynamic-forms/core/src/lib/model/dynamic-form-value-control.model.ts

Extends

DynamicFormControlModel

Index

Properties
Methods
Accessors

Constructor

Protected constructor(config: DynamicFormValueControlModelConfig, layout?: DynamicFormControlLayout)
Parameters :
Name Type Optional
config DynamicFormValueControlModelConfig<T> No
layout DynamicFormControlLayout Yes

Properties

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')
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

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

Accessors

value
getvalue()
setvalue(value)
Parameters :
Name Optional
value No
Returns : void
import { BehaviorSubject, Observable } from "rxjs";
import { DynamicFormControlModel, DynamicFormControlModelConfig } from "./dynamic-form-control.model";
import { DynamicFormControlLayout } from "./misc/dynamic-form-control-layout.model";
import { serializable } from "../decorator/serializable.decorator";
import { isBoolean, isObject } from "../utils/core.utils";

export interface DynamicFormValueControlModelConfig<T> extends DynamicFormControlModelConfig {

    additional?: { [key: string]: any };
    hint?: string;
    required?: boolean;
    tabIndex?: number;
    value?: T;
}

export abstract class DynamicFormValueControlModel<T> extends DynamicFormControlModel {

    @serializable() additional: { [key: string]: any } | null;
    @serializable() hint: string | null;
    @serializable() required: boolean;
    @serializable() tabIndex: number | null;
    @serializable("value") private _value: T | null;

    private readonly value$: BehaviorSubject<T>;

    readonly valueChanges: Observable<T>;

    protected constructor(config: DynamicFormValueControlModelConfig<T>, layout?: DynamicFormControlLayout) {

        super(config, layout);

        this.additional = isObject(config.additional) ? config.additional : null;
        this.hint = config.hint || null;
        this.required = isBoolean(config.required) ? config.required : false;
        this.tabIndex = config.tabIndex || null;

        this.value$ = new BehaviorSubject(config.value !== null && config.value !== undefined ? config.value : null);
        this.value$.subscribe(value => this._value = value);
        this.valueChanges = this.value$.asObservable();
    }

    get value(): T | null {
        return this.value$.getValue();
    }

    set value(value: T | null) {
        this.value$.next(value);
    }

    getAdditional(key: string, defaultValue?: any | null): any {
        return this.additional !== null && this.additional.hasOwnProperty(key) ? this.additional[key] : defaultValue;
    }
}

result-matching ""

    No results matching ""