All files / src/app/shared/formly-address-forms/components/formly-address-extension-form formly-address-extension-form.component.ts

100% Statements 8/8
100% Branches 1/1
100% Functions 3/3
100% Lines 8/8

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 563x 3x                     3x     4x         4x                                     4x 1x         1x                    
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
 
/**
 * Sub form with additional fields like email address and taxation id to extend the anonymous invoice address form.
 */
@Component({
  selector: 'ish-formly-address-extension-form',
  templateUrl: './formly-address-extension-form.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FormlyAddressExtensionFormComponent implements OnInit {
  @Input({ required: true }) form: FormGroup;
  @Input() businessCustomer: boolean;
  @Input() model: Partial<{ email: string; taxationId: string }> = {}; // model with data for the update mode.
 
  fields: FormlyFieldConfig[];
 
  ngOnInit() {
    this.fields = [
      {
        type: 'ish-fieldset-field',
        fieldGroup: [
          {
            key: 'email',
            type: 'ish-email-field',
            props: {
              required: true,
              label: 'checkout.addresses.email.label',
              customDescription: {
                key: 'account.address.email.hint',
              },
              postWrappers: [{ wrapper: 'description', index: -1 }],
            },
          },
        ],
      },
    ];
    if (this.businessCustomer) {
      this.fields = [this.createTaxationIDField(), ...this.fields];
    }
  }
 
  private createTaxationIDField(): FormlyFieldConfig {
    return {
      type: 'ish-fieldset-field',
      fieldGroup: [
        {
          type: '#taxationID',
        },
      ],
    };
  }
}