All files / formly/fields/text si-formly-text-display.component.ts

90.9% Statements 10/11
66.66% Branches 2/3
100% Functions 1/1
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                1x   14x 12x     2x 2x       2x   1x   1x 1x      
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { FieldType, FieldTypeConfig, FormlyModule } from '@ngx-formly/core';
import { SiTranslatePipe } from '@siemens/element-translate-ng/translate';
 
import { getFieldValue, getKeyPath } from '../../utils';
 
@Component({
  selector: 'si-formly-text-display',
  imports: [FormlyModule, ReactiveFormsModule, SiTranslatePipe],
  templateUrl: './si-formly-text-display.component.html'
})
export class SiFormlyTextDisplayComponent extends FieldType<FieldTypeConfig> {
  protected get value(): any {
    if (!this.props.key) {
      return this.formControl.value;
    }
 
    let sourceModel = this.model;
    Iif (Array.isArray(this.model)) {
      // The model is the arry itself when using this field as item into an array type...
      sourceModel = this.formControl.value;
    }
    if (this.props.key.indexOf('.') === -1) {
      // Special case for Array types:
      return sourceModel[this.props.key];
    }
    const path = getKeyPath(this.props.key);
    return getFieldValue(sourceModel, path);
  }
}