File

feature-libs/product-configurator/textfield/components/input-field/configurator-textfield-input-field.component.ts

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-textfield-input-field
templateUrl ./configurator-textfield-input-field.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor()

Inputs

attribute
Type : ConfiguratorTextfield.ConfigurationInfo

Outputs

inputChange
Type : EventEmitter

Methods

getId
getId(attribute: ConfiguratorTextfield.ConfigurationInfo)

Compiles an ID for the attribute value by using the label from the backend

Parameters :
Name Type Optional Description
attribute ConfiguratorTextfield.ConfigurationInfo No

Textfield configurator attribute. Carries the attribute label information from the backend

Returns : string

ID

getIdLabel
getIdLabel(attribute: ConfiguratorTextfield.ConfigurationInfo)

Compiles an ID for the attribute label by using the label from the backend and a prefix 'label'

Parameters :
Name Type Optional Description
attribute ConfiguratorTextfield.ConfigurationInfo No

Textfield configurator attribute. Carries the attribute label information from the backend

Returns : string

ID

Protected getLabelForIdGeneration
getLabelForIdGeneration(attribute: ConfiguratorTextfield.ConfigurationInfo)
Parameters :
Name Type Optional
attribute ConfiguratorTextfield.ConfigurationInfo No
Returns : string
ngOnInit
ngOnInit()
Returns : void
onInputChange
onInputChange()

Triggered if an attribute value is changed. Triggers the emission of the inputChange event emitter that is in turn received in the form component

Returns : void

Properties

attribute
Type : ConfiguratorTextfield.ConfigurationInfo
Decorators :
@Input()
attributeInputForm
Default value : new FormControl('')
inputChange
Default value : new EventEmitter<ConfiguratorTextfield.ConfigurationInfo>()
Decorators :
@Output()
PREFIX_TEXTFIELD
Type : string
Default value : 'cx-configurator-textfield'
import {
  ChangeDetectionStrategy,
  Component,
  EventEmitter,
  Input,
  OnInit,
  Output,
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { ConfiguratorTextfield } from '../../core/model/configurator-textfield.model';

@Component({
  selector: 'cx-configurator-textfield-input-field',
  templateUrl: './configurator-textfield-input-field.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorTextfieldInputFieldComponent implements OnInit {
  PREFIX_TEXTFIELD = 'cx-configurator-textfield';
  attributeInputForm = new FormControl('');

  @Input() attribute: ConfiguratorTextfield.ConfigurationInfo;
  @Output()
  inputChange = new EventEmitter<ConfiguratorTextfield.ConfigurationInfo>();

  constructor() {}

  ngOnInit() {
    this.attributeInputForm.setValue(this.attribute.configurationValue);
  }
  /**
   * Triggered if an attribute value is changed. Triggers the emission of the inputChange event emitter that is
   * in turn received in the form component
   */
  onInputChange(): void {
    const attribute: ConfiguratorTextfield.ConfigurationInfo = {
      configurationLabel: this.attribute.configurationLabel,
      configurationValue: this.attributeInputForm.value,
    };

    this.inputChange.emit(attribute);
  }
  /**
   * Compiles an ID for the attribute label by using the label from the backend and a prefix 'label'
   * @param attribute Textfield configurator attribute. Carries the attribute label information from the backend
   * @returns ID
   */
  getIdLabel(attribute: ConfiguratorTextfield.ConfigurationInfo): string {
    return (
      this.PREFIX_TEXTFIELD + 'label' + this.getLabelForIdGeneration(attribute)
    );
  }
  /**
   * Compiles an ID for the attribute value by using the label from the backend
   * @param attribute Textfield configurator attribute. Carries the attribute label information from the backend
   * @returns ID
   */
  getId(attribute: ConfiguratorTextfield.ConfigurationInfo): string {
    return this.PREFIX_TEXTFIELD + this.getLabelForIdGeneration(attribute);
  }

  protected getLabelForIdGeneration(
    attribute: ConfiguratorTextfield.ConfigurationInfo
  ): string {
    //replace white spaces with an empty string
    return attribute.configurationLabel.replace(/\s/g, '');
  }
}
<label
  id="{{ getIdLabel(attribute) }}"
  class="cx-configurator-textfield-label"
  [attr.aria-label]="attribute.configurationLabel"
  >{{ attribute.configurationLabel }}</label
>
<div class="form-group">
  <input
    [formControl]="attributeInputForm"
    class="form-control"
    (change)="onInputChange()"
    attr.aria-labelledby="{{ getIdLabel(attribute) }}"
  />
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""