diff --git a/src/app/shared/formly-address-forms/configurations/address-form.configuration.ts b/src/app/shared/formly-address-forms/configurations/address-form.configuration.ts
index 8c95fe98f1e..00df0adcd9d 100644
--- a/src/app/shared/formly-address-forms/configurations/address-form.configuration.ts
+++ b/src/app/shared/formly-address-forms/configurations/address-form.configuration.ts
@@ -1,7 +1,6 @@
import { FormlyFieldConfig } from '@ngx-formly/core';
import { Address } from 'ish-core/models/address/address.model';
-import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';
/*
* Abstract class that valid address configurations have to extend.
@@ -16,129 +15,6 @@ export abstract class AddressFormConfiguration {
abstract getModel(model?: Partial
): Partial;
}
-
-// post-processing method that will be called for every field configuration
-function applyStandardStyles(config: FormlyFieldConfig): FormlyFieldConfig {
- /* do some customization here */
- return config;
-}
-
-// collection of standard address form field configurations
-const standardFields: { [key: string]: Omit } = {
- companyName1: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.address.company_name.label',
- required: true,
- },
- validation: {
- messages: {
- required: 'account.address.company_name.error.required',
- },
- },
- },
- companyName2: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.address.company_name_2.label',
- required: false,
- },
- },
- firstName: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.default_address.firstname.label',
- required: true,
- },
- validators: {
- validation: [SpecialValidators.noSpecialChars],
- },
- validation: {
- messages: {
- required: 'account.address.firstname.missing.error',
- noSpecialChars: 'account.name.error.forbidden.chars',
- },
- },
- },
- lastName: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.default_address.lastname.label',
- required: true,
- },
- validators: {
- validation: [SpecialValidators.noSpecialChars],
- },
- validation: {
- messages: {
- required: 'account.address.lastname.missing.error',
- noSpecialChars: 'account.name.error.forbidden.chars',
- },
- },
- },
- addressLine1: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.default_address.street.label',
- required: true,
- },
- validation: {
- messages: {
- required: 'account.address.address1.missing.error',
- },
- },
- },
- addressLine2: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.default_address.street2.label',
- required: false,
- },
- },
- postalCode: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.default_address.postalcode.label',
- required: true,
- },
- validation: {
- messages: {
- required: 'account.address.postalcode.missing.error',
- },
- },
- },
- city: {
- type: 'ish-text-input-field',
- templateOptions: {
- label: 'account.default_address.city.label',
- required: true,
- },
- validation: {
- messages: {
- required: 'account.address.city.missing.error',
- },
- },
- },
- phoneHome: {
- type: 'ish-phone-field',
- templateOptions: {
- label: 'account.profile.phone.label',
- required: false,
- },
- },
- fax: {},
-};
-
-function standardField(key: keyof Address | (FormlyFieldConfig & { key: keyof Address })): FormlyFieldConfig {
- if (typeof key === 'string') {
- if (!standardFields[key]) {
- throw new TypeError(`Cannot find "${key}" in standard fields.`);
- }
- return applyStandardStyles({ key, ...standardFields[key] });
- }
- return applyStandardStyles(key);
-}
-
// helper method to reduce repetition when defining address form configurations containing standard fields
export function addressesFieldConfiguration(
keys: (
@@ -154,7 +30,9 @@ export function addressesFieldConfiguration(
type: 'ish-fieldset-field',
fieldGroup: addressesFieldConfiguration(key),
}
- : standardField(key)
+ : typeof key === 'string'
+ ? { type: `#${key}` }
+ : key
)
.filter(x => !!x);
}
diff --git a/src/app/shared/formly-address-forms/configurations/de/address-form-de.configuration.ts b/src/app/shared/formly-address-forms/configurations/de/address-form-de.configuration.ts
index 8375b7d9025..14455aab6d2 100644
--- a/src/app/shared/formly-address-forms/configurations/de/address-form-de.configuration.ts
+++ b/src/app/shared/formly-address-forms/configurations/de/address-form-de.configuration.ts
@@ -2,22 +2,17 @@ import { Injectable } from '@angular/core';
import { Validators } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';
-import { of } from 'rxjs';
import { Address } from 'ish-core/models/address/address.model';
import {
AddressFormConfiguration,
addressesFieldConfiguration,
} from 'ish-shared/formly-address-forms/configurations/address-form.configuration';
-import { FormsService } from 'ish-shared/forms/utils/forms.service';
@Injectable()
export class AddressFormDEConfiguration extends AddressFormConfiguration {
countryCode = 'DE';
- constructor(private formsService: FormsService) {
- super();
- }
getModel(model: Partial = {}): Partial {
return pick(
model,
@@ -38,19 +33,7 @@ export class AddressFormDEConfiguration extends AddressFormConfiguration {
getFieldConfiguration(): FormlyFieldConfig[] {
return addressesFieldConfiguration([
this.businessCustomer && !this.shortForm && ['companyName1', 'companyName2'],
- !this.shortForm && [
- {
- key: 'title',
- type: 'ish-select-field',
- templateOptions: {
- label: 'account.default_address.title.label',
- options: of(this.formsService.getSalutationOptionsForCountryCode(this.countryCode)),
- placeholder: 'account.option.select.text',
- },
- },
- 'firstName',
- 'lastName',
- ],
+ !this.shortForm && ['title', 'firstName', 'lastName'],
[
'addressLine1',
'addressLine2',
@@ -58,7 +41,7 @@ export class AddressFormDEConfiguration extends AddressFormConfiguration {
key: 'addressLine3',
type: 'ish-text-input-field',
templateOptions: {
- label: 'account.default_address.street3.label',
+ label: 'account.address.street3.label',
required: false,
},
},
@@ -66,10 +49,8 @@ export class AddressFormDEConfiguration extends AddressFormConfiguration {
[
{
key: 'postalCode',
- type: 'ish-text-input-field',
+ type: '#postalCode',
templateOptions: {
- label: 'account.default_address.postalcode.label',
- required: true,
maxLength: 5,
},
validators: {
@@ -77,7 +58,6 @@ export class AddressFormDEConfiguration extends AddressFormConfiguration {
},
validation: {
messages: {
- required: 'account.address.postalcode.missing.error',
pattern: 'account.address.de.postalcode.error.regexp',
},
},
diff --git a/src/app/shared/formly-address-forms/configurations/fr/address-form-fr.configuration.ts b/src/app/shared/formly-address-forms/configurations/fr/address-form-fr.configuration.ts
index c976b4ffc5e..7bda5087560 100644
--- a/src/app/shared/formly-address-forms/configurations/fr/address-form-fr.configuration.ts
+++ b/src/app/shared/formly-address-forms/configurations/fr/address-form-fr.configuration.ts
@@ -2,23 +2,17 @@ import { Injectable } from '@angular/core';
import { Validators } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';
-import { of } from 'rxjs';
import { Address } from 'ish-core/models/address/address.model';
import {
AddressFormConfiguration,
addressesFieldConfiguration,
} from 'ish-shared/formly-address-forms/configurations/address-form.configuration';
-import { FormsService } from 'ish-shared/forms/utils/forms.service';
@Injectable()
export class AddressFormFRConfiguration extends AddressFormConfiguration {
countryCode = 'FR';
- constructor(private formsService: FormsService) {
- super();
- }
-
getModel(model: Partial = {}): Partial {
return pick(
model,
@@ -38,27 +32,13 @@ export class AddressFormFRConfiguration extends AddressFormConfiguration {
getFieldConfiguration(): FormlyFieldConfig[] {
return addressesFieldConfiguration([
this.businessCustomer && !this.shortForm && ['companyName1', 'companyName2'],
- !this.shortForm && [
- {
- key: 'title',
- type: 'ish-select-field',
- templateOptions: {
- label: 'account.default_address.title.label',
- options: of(this.formsService.getSalutationOptionsForCountryCode(this.countryCode)),
- placeholder: 'account.option.select.text',
- },
- },
- 'firstName',
- 'lastName',
- ],
+ !this.shortForm && ['title', 'firstName', 'lastName'],
['addressLine1', 'addressLine2'],
[
{
key: 'postalCode',
- type: 'ish-text-input-field',
+ type: '#postalCode',
templateOptions: {
- label: 'account.default_address.postalcode.label',
- required: true,
maxLength: 5,
},
validators: {
@@ -66,8 +46,7 @@ export class AddressFormFRConfiguration extends AddressFormConfiguration {
},
validation: {
messages: {
- required: 'account.address.postalcode.missing.error',
- pattern: 'account.address.de.postalcode.error.regexp',
+ pattern: 'account.address.fr.postalcode.error.regexp',
},
},
},
diff --git a/src/app/shared/formly-address-forms/configurations/gb/address-form-gb.configuration.ts b/src/app/shared/formly-address-forms/configurations/gb/address-form-gb.configuration.ts
index a2c92f305d7..fea051b0712 100644
--- a/src/app/shared/formly-address-forms/configurations/gb/address-form-gb.configuration.ts
+++ b/src/app/shared/formly-address-forms/configurations/gb/address-form-gb.configuration.ts
@@ -2,23 +2,17 @@ import { Injectable } from '@angular/core';
import { Validators } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';
-import { of } from 'rxjs';
import { Address } from 'ish-core/models/address/address.model';
import {
AddressFormConfiguration,
addressesFieldConfiguration,
} from 'ish-shared/formly-address-forms/configurations/address-form.configuration';
-import { FormsService } from 'ish-shared/forms/utils/forms.service';
@Injectable()
export class AddressFormGBConfiguration extends AddressFormConfiguration {
countryCode = 'GB';
- constructor(private formsService: FormsService) {
- super();
- }
-
getModel(model: Partial = {}): Partial {
return pick(
model,
@@ -39,26 +33,14 @@ export class AddressFormGBConfiguration extends AddressFormConfiguration {
getFieldConfiguration(): FormlyFieldConfig[] {
return addressesFieldConfiguration([
this.businessCustomer && !this.shortForm && ['companyName1', 'companyName2'],
- !this.shortForm && [
- {
- key: 'title',
- type: 'ish-select-field',
- templateOptions: {
- label: 'account.default_address.title.label',
- options: of(this.formsService.getSalutationOptionsForCountryCode(this.countryCode)),
- placeholder: 'account.option.select.text',
- },
- },
- 'firstName',
- 'lastName',
- ],
+ !this.shortForm && ['title', 'firstName', 'lastName'],
[
'addressLine1',
'addressLine2',
{
key: 'addressLine3',
templateOptions: {
- label: 'account.default_address.uk.locality.label',
+ label: 'account.address.uk.locality.label',
required: false,
},
type: 'ish-text-input-field',
@@ -68,10 +50,7 @@ export class AddressFormGBConfiguration extends AddressFormConfiguration {
'city',
{
key: 'postalCode',
- templateOptions: {
- label: 'account.default_address.postalcode.label',
- required: true,
- },
+ type: '#postalCode',
validators: {
validation: [
Validators.pattern(
@@ -82,11 +61,9 @@ export class AddressFormGBConfiguration extends AddressFormConfiguration {
},
validation: {
messages: {
- required: 'account.address.postalcode.missing.error',
pattern: 'account.address.uk.postalcode.error.regexp',
},
},
- type: 'ish-text-input-field',
},
],
!this.shortForm ? 'phoneHome' : undefined,
diff --git a/src/app/shared/formly-address-forms/configurations/us/address-form-us.configuration.ts b/src/app/shared/formly-address-forms/configurations/us/address-form-us.configuration.ts
index 3b38e8eb392..0556cf56e27 100644
--- a/src/app/shared/formly-address-forms/configurations/us/address-form-us.configuration.ts
+++ b/src/app/shared/formly-address-forms/configurations/us/address-form-us.configuration.ts
@@ -42,22 +42,15 @@ export class AddressFormUSConfiguration extends AddressFormConfiguration {
[
{
key: 'city',
- type: 'ish-text-input-field',
+ type: '#city',
templateOptions: {
postWrappers: [{ wrapper: 'tooltip', index: -1 }],
- label: 'account.default_address.city.label',
- required: true,
tooltip: {
link: 'account.address.apo_fpo.link',
text: 'account.address.apo_fpo.tooltip',
title: 'account.address.apo_fpo.tooltip.headline',
},
},
- validation: {
- messages: {
- required: 'account.address.city.missing.error',
- },
- },
},
{
key: 'mainDivisionCode',
@@ -78,20 +71,15 @@ export class AddressFormUSConfiguration extends AddressFormConfiguration {
},
{
key: 'postalCode',
- templateOptions: {
- label: 'account.default_address.postalcode.label',
- required: true,
- },
+ type: '#postalCode',
validators: {
validation: [Validators.pattern('^[0-9]{5}$|^[0-9]{5}-[0-9]{4}$')],
},
validation: {
messages: {
- required: 'account.address.postalcode.missing.error',
pattern: 'account.address.us.postalcode.error.regexp',
},
},
- type: 'ish-text-input-field',
},
],
!this.shortForm ? 'phoneHome' : undefined,