File

feature-libs/product-configurator/rulebased/components/attribute/footer/configurator-attribute-footer.component.ts

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-attribute-footer
templateUrl ./configurator-attribute-footer.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(configUtils: ConfiguratorStorefrontUtilsService)
Parameters :
Name Type Optional
configUtils ConfiguratorStorefrontUtilsService No

Inputs

attribute
Type : Configurator.Attribute
groupId
Type : string
owner
Type : CommonConfigurator.Owner

Methods

isUserInputEmpty
isUserInputEmpty(input?: string)

Checks if attribute is a user input typed attribute with empty value. Method will return false for domain based attributes

Parameters :
Name Type Optional Description
input string Yes
  • user input
Returns : boolean
Protected needsUserInputMessage
needsUserInputMessage()
Returns : boolean
ngOnInit
ngOnInit()
Returns : void

Properties

attribute
Type : Configurator.Attribute
Decorators :
@Input()
groupId
Type : string
Decorators :
@Input()
iconType
Default value : ICON_TYPE
owner
Type : CommonConfigurator.Owner
Decorators :
@Input()
showRequiredMessageForUserInput$
Type : Observable<boolean>
import {
  ChangeDetectionStrategy,
  Component,
  Input,
  OnInit,
} from '@angular/core';
import { CommonConfigurator } from '@spartacus/product-configurator/common';
import { ICON_TYPE } from '@spartacus/storefront';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Configurator } from '../../../core/model/configurator.model';
import { ConfiguratorStorefrontUtilsService } from '../../service/configurator-storefront-utils.service';

@Component({
  selector: 'cx-configurator-attribute-footer',
  templateUrl: './configurator-attribute-footer.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorAttributeFooterComponent implements OnInit {
  @Input() attribute: Configurator.Attribute;
  @Input() owner: CommonConfigurator.Owner;
  @Input() groupId: string;

  constructor(protected configUtils: ConfiguratorStorefrontUtilsService) {}

  iconType = ICON_TYPE;
  showRequiredMessageForUserInput$: Observable<boolean>;

  ngOnInit(): void {
    /**
     * Show message that indicates that attribute is required in case attribute is a
     * free input field
     */
    this.showRequiredMessageForUserInput$ = this.configUtils
      .isCartEntryOrGroupVisited(this.owner, this.groupId)
      .pipe(map((result) => (result ? this.needsUserInputMessage() : false)));
  }

  /**
   * Checks if attribute is a user input typed attribute with empty value.
   * Method will return false for domain based attributes
   * @param {string} input - user input
   */
  isUserInputEmpty(input?: string): boolean {
    return input !== undefined && (!input.trim() || 0 === input.length);
  }

  protected needsUserInputMessage(): boolean {
    const uiType = this.attribute.uiType;
    const needsMessage =
      this.attribute.required &&
      this.attribute.incomplete &&
      (uiType === Configurator.UiType.STRING ||
        uiType === Configurator.UiType.NUMERIC) &&
      this.isUserInputEmpty(this.attribute.userInput);
    return needsMessage ?? false;
  }
}
<div
  *ngIf="showRequiredMessageForUserInput$ | async"
  class="cx-required-error-msg"
>
  <cx-icon [type]="iconType.ERROR"></cx-icon>
  {{ 'configurator.attribute.defaultRequiredMessage' | cxTranslate }}
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""