File

projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts

Extends

DataField

Index

Properties
Methods
Accessors

Constructor

constructor(stringId: string, title: string, value: string, _choices: Array<EnumerationFieldValue>, behavior: Behavior, placeholder?: string, description?: string, layout?: Layout, _fieldType, validations?: Array<Validation>, component?: Component, parentTaskId?: string)
Parameters :
Name Type Optional
stringId string No
title string No
value string No
_choices Array<EnumerationFieldValue> No
behavior Behavior No
placeholder string Yes
description string Yes
layout Layout Yes
_fieldType No
validations Array<Validation> Yes
component Component Yes
parentTaskId string Yes

Properties

Protected _updatedChoices
Type : Subject<void>
Protected REQUEST_DEBOUNCE_TIME
Type : number
Default value : 600
Protected _blockSubscription
Type : Subscription
Inherited from DataField
Defined in DataField:71
Protected _formControlValueSubscription
Type : Subscription
Inherited from DataField
Defined in DataField:73
Protected _initializedSubscription
Type : Subscription
Inherited from DataField
Defined in DataField:103

Stores the last subscription to the _initialized$ Stream, to prevent multiple block events from executing at the same time

Protected _localLayout
Type : Layout
Inherited from DataField
Defined in DataField:115

Stores a copy of the fields layout, that can be modified by the layouting algorithm as needed without affecting the base configuration.

Protected _myValueSubscription
Type : Subscription
Inherited from DataField
Defined in DataField:74
Protected _touchSubscription
Type : Subscription
Inherited from DataField
Defined in DataField:72
Protected _updateSubscription
Type : Subscription
Inherited from DataField
Defined in DataField:70
Protected _validators
Type : Array<ValidatorFn>
Inherited from DataField
Defined in DataField:97

Validators resolved from field validations

Protected layoutSubject
Type : BehaviorSubject<Layout>
Inherited from DataField
Defined in DataField:120

Listens for layout changes

Public Optional validations
Type : Array<Validation>
Inherited from DataField
Defined in DataField:152

Methods

Public destroy
destroy()
Inherited from DataField
Defined in DataField:66
Returns : void
Public getTypedComponentType
getTypedComponentType()
Inherited from DataField
Defined in DataField:54
Returns : string
Public getUpdateOnStrategy
getUpdateOnStrategy()
Inherited from DataField
Defined in DataField:46
Returns : UpdateOnStrategy
Protected resolveFormControlValidators
resolveFormControlValidators()
Inherited from DataField
Defined in DataField:71
Returns : Array<ValidatorFn>
Public updateChoice
updateChoice()
Returns : void
Public valueChanges
valueChanges()
Inherited from DataField
Defined in DataField:50
Returns : Observable<string>
Protected _determineFormControlValidity
_determineFormControlValidity(formControl: FormControl)
Inherited from DataField
Defined in DataField:490

Computes whether the FormControl si valid.

Parameters :
Name Type Optional Description
formControl FormControl No

check form control

Returns : boolean
Public applyChange
applyChange(change: Change)
Inherited from DataField
Defined in DataField:555

Updates the state of this data field model object.

Also see ChangedFields.

Parameters :
Name Type Optional Description
change Change No
  • object describing the changes - returned from backend

Also see {

Returns : void
Protected calculateValidity
calculateValidity(forValidRequired: boolean, formControl: FormControl)
Inherited from DataField
Defined in DataField:598
Parameters :
Name Type Optional
forValidRequired boolean No
formControl FormControl No
Returns : boolean
Public clearValidators
clearValidators()
Inherited from DataField
Defined in DataField:530
Returns : void
Public componentChange$
componentChange$()
Inherited from DataField
Defined in DataField:307
Public disconnectFormControl
disconnectFormControl()
Inherited from DataField
Defined in DataField:433
Returns : void
Public focus
focus()
Inherited from DataField
Defined in DataField:357
Returns : void
Public getComponentType
getComponentType()
Inherited from DataField
Defined in DataField:387

This function resolve type of component for HTML

Returns : string

type of component in string

Public isInvalid
isInvalid(formControl: FormControl)
Inherited from DataField
Defined in DataField:615
Parameters :
Name Type Optional
formControl FormControl No
Returns : boolean
Public registerFormControl
registerFormControl(formControl: FormControl)
Inherited from DataField
Defined in DataField:403
Parameters :
Name Type Optional
formControl FormControl No
Returns : void
Public replaceValidations
replaceValidations(validations: Array<Validation>)
Inherited from DataField
Defined in DataField:525
Parameters :
Name Type Optional
validations Array<Validation> No
Returns : void
Public resetLocalLayout
resetLocalLayout()
Inherited from DataField
Defined in DataField:622

Copies the layout settings into the local layout.

Returns : void
Public resolveAppearance
resolveAppearance(config: ConfigurationService)
Inherited from DataField
Defined in DataField:571
Parameters :
Name Type Optional
config ConfigurationService No
Returns : void
Public resolvePrevValue
resolvePrevValue(value: T)
Inherited from DataField
Defined in DataField:591
Parameters :
Name Type Optional
value T No
Returns : void
Protected resolveValidations
resolveValidations()
Inherited from DataField
Defined in DataField:534
Returns : Array<ValidatorFn>
Public revertToPreviousValue
revertToPreviousValue()
Inherited from DataField
Defined in DataField:311
Returns : void
Protected subscribeToInnerSubjects
subscribeToInnerSubjects(formControl: FormControl)
Inherited from DataField
Defined in DataField:458
Parameters :
Name Type Optional
formControl FormControl No
Returns : void
Public update
update()
Inherited from DataField
Defined in DataField:341
Returns : void
Protected updateFormControlState
updateFormControlState(formControl: FormControl)
Inherited from DataField
Defined in DataField:452
Parameters :
Name Type Optional
formControl FormControl No
Returns : void
Protected valueEquality
valueEquality(a: T, b: T)
Inherited from DataField
Defined in DataField:545

Determines if two values of the data field are equal.

a === b equality is used by default. If you want different behavior override this method.

Parameters :
Name Type Optional Description
a T No
  • first compared value
b T No
  • second compared value
Returns : boolean
Public valueWithoutChange
valueWithoutChange(value: T)
Inherited from DataField
Defined in DataField:235
Parameters :
Name Type Optional
value T No
Returns : void

Accessors

choices
getchoices()
setchoices(choices: Array<EnumerationFieldValue>)
Parameters :
Name Type Optional
choices Array<EnumerationFieldValue> No
Returns : void
fieldType
getfieldType()
updatedChoices
getupdatedChoices()
import {DataField} from '../../models/abstract-data-field';
import {Behavior} from '../../models/behavior';
import {Layout} from '../../models/layout';
import {AbstractControl, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
import {FieldTypeResource} from '../../../task-content/model/field-type-resource';
import {Component, ComponentPrefixes} from '../../models/component';
import {Validation} from '../../models/validation';
import {Observable, Subject} from "rxjs";
import {debounceTime} from "rxjs/operators";
import {UpdateOnStrategy, UpdateStrategy} from "../../models/update-strategy";

export interface EnumerationFieldValue {
    key: string;
    value: string;
}

export enum EnumerationFieldValidation {
    WRONG_VALUE = 'wrongValue',
    REQUIRED = 'required'
}

export class EnumerationField extends DataField<string> {
    protected REQUEST_DEBOUNCE_TIME = 600;
    protected _updatedChoices: Subject<void>;

    constructor(stringId: string, title: string, value: string,
                protected _choices: Array<EnumerationFieldValue>, behavior: Behavior, placeholder?: string, description?: string,
                layout?: Layout, protected readonly _fieldType = FieldTypeResource.ENUMERATION,
                validations?: Array<Validation>, component?: Component, parentTaskId?: string) {
        super(stringId, title, value, behavior, placeholder, description, layout, validations, component, parentTaskId);
        this._updatedChoices = new Subject<void>();
    }

    set choices(choices: Array<EnumerationFieldValue>) {
        this._choices = choices;
    }

    get choices(): Array<EnumerationFieldValue> {
        return this._choices;
    }

    get fieldType(): FieldTypeResource {
        return this._fieldType;
    }

    public getUpdateOnStrategy(): UpdateOnStrategy {
        return UpdateStrategy.CHANGE;
    }

    public valueChanges(): Observable<string> {
        return this._value.pipe(debounceTime(this.REQUEST_DEBOUNCE_TIME));
    }

    public getTypedComponentType(): string {
        return ComponentPrefixes.ENUMERATION + this.getComponentType();
    }

    get updatedChoices(): Observable<void> {
        return this._updatedChoices.asObservable();
    }

    public updateChoice(): void {
        this._updatedChoices.next();
    }

    public destroy(): void {
        super.destroy();
        this._updatedChoices.complete();
    }

    protected resolveFormControlValidators(): Array<ValidatorFn> {
        const result = [];

        if (this.behavior.required) {
            result.push(Validators.required);
        }
        result.push((control: AbstractControl) => this.checkKey(control));

        return result;
    }

    private checkKey(control: AbstractControl): ValidationErrors | null {
        if (this._choices === undefined || this._choices.length === 0 || control.value === '' || control.value === undefined) {
            return null;
        }
        return this._choices.find(choice => choice.key === control.value || control.value === null) ? null : {wrongValue: true};
    }
}

result-matching ""

    No results matching ""