@internetarchive/donation-form 1.0.3-webdev-8114.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,11 +22,20 @@ export declare class ContactForm extends LitElement {
|
|
|
22
22
|
countryCodeAlpha2Field: HTMLSelectElement;
|
|
23
23
|
errorMessage: HTMLDivElement;
|
|
24
24
|
form: HTMLFormElement;
|
|
25
|
+
/** @keyof countries */
|
|
25
26
|
selectedCountry: string;
|
|
26
27
|
donorEmail: string;
|
|
27
28
|
updated(changed: PropertyValues): void;
|
|
28
29
|
reportValidity(): boolean;
|
|
30
|
+
private validateFormFields;
|
|
31
|
+
private validateForm;
|
|
29
32
|
focus(): void;
|
|
33
|
+
private minTwoCharPattern;
|
|
34
|
+
private minTwoCharValidationMessage;
|
|
35
|
+
private streetAddressPattern;
|
|
36
|
+
private streetAddressValidationMessage;
|
|
37
|
+
private zipCodePattern;
|
|
38
|
+
private zipCodeValidationMessage;
|
|
30
39
|
/** @inheritdoc */
|
|
31
40
|
render(): TemplateResult;
|
|
32
41
|
private get regionAndPostalCodeRequired();
|
|
@@ -9,11 +9,22 @@ import emailImg from '@internetarchive/icon-email/index.js';
|
|
|
9
9
|
import localePinImg from '@internetarchive/icon-locale-pin/index.js';
|
|
10
10
|
import userIcon from '@internetarchive/icon-user/index.js';
|
|
11
11
|
import { countries } from './countries';
|
|
12
|
+
import { msg } from '@lit/localize';
|
|
12
13
|
let ContactForm = class ContactForm extends LitElement {
|
|
13
14
|
constructor() {
|
|
14
15
|
super(...arguments);
|
|
16
|
+
/** @keyof countries */
|
|
15
17
|
this.selectedCountry = 'US';
|
|
16
18
|
this.donorEmail = '';
|
|
19
|
+
// minimum two non-whitespace characters
|
|
20
|
+
this.minTwoCharPattern = '.*\\S{2,}.*';
|
|
21
|
+
this.minTwoCharValidationMessage = msg('Enter at least two characters');
|
|
22
|
+
// at least two non-whitespace characters with at least two characters in between them
|
|
23
|
+
this.streetAddressPattern = '.*?\\S.{2,}\\S.*?';
|
|
24
|
+
this.streetAddressValidationMessage = msg('Enter at least four characters');
|
|
25
|
+
// matches 12345 or 12345-6789 or 123456789
|
|
26
|
+
this.zipCodePattern = '^\\d{5}(-?\\d{4})?$';
|
|
27
|
+
this.zipCodeValidationMessage = msg('Enter a valid 5 or 9 digit zip/postal code');
|
|
17
28
|
}
|
|
18
29
|
updated(changed) {
|
|
19
30
|
var _a;
|
|
@@ -22,25 +33,30 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
reportValidity() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
this.validateFormFields();
|
|
37
|
+
return this.validateForm();
|
|
38
|
+
}
|
|
39
|
+
// validate each field and set the error state on the badged-inputs
|
|
40
|
+
validateFormFields() {
|
|
41
|
+
const fields = [
|
|
42
|
+
{ badgedInput: this.emailBadgedInput, inputField: this.emailField },
|
|
43
|
+
{ badgedInput: this.firstNameBadgedInput, inputField: this.firstNameField },
|
|
44
|
+
{ badgedInput: this.lastNameBadgedInput, inputField: this.lastNameField },
|
|
45
|
+
{ badgedInput: this.streetAddressBadgedInput, inputField: this.streetAddressField },
|
|
46
|
+
{ badgedInput: this.extendedAddressBadgedInput, inputField: this.extendedAddressField },
|
|
47
|
+
{ badgedInput: this.localityBadgedInput, inputField: this.localityField },
|
|
48
|
+
{ badgedInput: this.regionBadgedInput, inputField: this.regionField },
|
|
49
|
+
{ badgedInput: this.postalBadgedInput, inputField: this.postalCodeField },
|
|
33
50
|
];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const fieldValid = inputElement.checkValidity();
|
|
37
|
-
isValid = isValid && fieldValid;
|
|
38
|
-
if (!fieldValid) {
|
|
39
|
-
badgedInput.error = true;
|
|
40
|
-
}
|
|
51
|
+
fields.forEach(({ badgedInput, inputField }) => {
|
|
52
|
+
badgedInput.error = !inputField.checkValidity();
|
|
41
53
|
});
|
|
54
|
+
}
|
|
55
|
+
// validate the overall form and show error messages
|
|
56
|
+
validateForm() {
|
|
57
|
+
const isValid = this.form.reportValidity();
|
|
42
58
|
if (!isValid) {
|
|
43
|
-
this.errorMessage.innerText = 'Please enter any missing or invalid contact information below';
|
|
59
|
+
this.errorMessage.innerText = msg('Please enter any missing or invalid contact information below');
|
|
44
60
|
}
|
|
45
61
|
else {
|
|
46
62
|
this.errorMessage.innerText = '';
|
|
@@ -78,7 +94,8 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
78
94
|
placeholder: 'First name',
|
|
79
95
|
name: 'fname',
|
|
80
96
|
required: true,
|
|
81
|
-
validationPattern:
|
|
97
|
+
validationPattern: this.minTwoCharPattern,
|
|
98
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
82
99
|
maxlength: 255,
|
|
83
100
|
autocomplete: 'given-name',
|
|
84
101
|
icon: userIcon,
|
|
@@ -91,7 +108,8 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
91
108
|
name: 'lname',
|
|
92
109
|
autocomplete: 'family-name',
|
|
93
110
|
required: true,
|
|
94
|
-
validationPattern:
|
|
111
|
+
validationPattern: this.minTwoCharPattern,
|
|
112
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
95
113
|
maxlength: 255,
|
|
96
114
|
})}
|
|
97
115
|
</div>
|
|
@@ -105,7 +123,8 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
105
123
|
autocomplete: 'address-line1',
|
|
106
124
|
icon: localePinImg,
|
|
107
125
|
name: 'street-address',
|
|
108
|
-
validationPattern:
|
|
126
|
+
validationPattern: this.streetAddressPattern,
|
|
127
|
+
validationMessage: this.streetAddressValidationMessage,
|
|
109
128
|
})}
|
|
110
129
|
</div>
|
|
111
130
|
<div class="row">
|
|
@@ -124,7 +143,8 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
124
143
|
autocomplete: 'address-level2',
|
|
125
144
|
required: true,
|
|
126
145
|
name: 'locality',
|
|
127
|
-
validationPattern:
|
|
146
|
+
validationPattern: this.minTwoCharPattern,
|
|
147
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
128
148
|
})}
|
|
129
149
|
</div>
|
|
130
150
|
<div class="row">
|
|
@@ -134,7 +154,8 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
134
154
|
autocomplete: 'address-level1',
|
|
135
155
|
required: this.regionAndPostalCodeRequired,
|
|
136
156
|
name: 'region',
|
|
137
|
-
validationPattern:
|
|
157
|
+
validationPattern: this.minTwoCharPattern,
|
|
158
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
138
159
|
})}
|
|
139
160
|
${this.generateInput({
|
|
140
161
|
id: 'donation-contact-form-postal-code',
|
|
@@ -142,7 +163,8 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
142
163
|
autocomplete: 'postal-code',
|
|
143
164
|
required: this.regionAndPostalCodeRequired,
|
|
144
165
|
name: 'postal',
|
|
145
|
-
validationPattern:
|
|
166
|
+
validationPattern: this.zipCodePattern,
|
|
167
|
+
validationMessage: this.zipCodeValidationMessage,
|
|
146
168
|
iconSpaceOption: SpacerOption.CompressSpace,
|
|
147
169
|
})}
|
|
148
170
|
</div>
|
|
@@ -216,6 +238,7 @@ let ContactForm = class ContactForm extends LitElement {
|
|
|
216
238
|
minlength=${ifDefined(options.minlength)}
|
|
217
239
|
autocomplete=${(_d = options.autocomplete) !== null && _d !== void 0 ? _d : 'on'}
|
|
218
240
|
pattern=${ifDefined(options.validationPattern)}
|
|
241
|
+
title=${ifDefined(options.validationMessage)}
|
|
219
242
|
@focus=${this.inputFocused}
|
|
220
243
|
?required=${required}
|
|
221
244
|
/>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contact-form.js","sourceRoot":"","sources":["../../../../src/form-elements/contact-form/contact-form.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAA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C,KAAK,CAAC,mCAAmC,CAAC;mDAAmC;AAEvB;IAAtD,KAAK,CAAC,8CAA8C,CAAC;wDAAmC;AAC9C;IAA1C,KAAK,CAAC,kCAAkC,CAAC;kDAAkC;AAEnB;IAAxD,KAAK,CAAC,gDAAgD,CAAC;sDAAiC;AAC5C;IAA5C,KAAK,CAAC,oCAAoC,CAAC;oDAAoC;AAGhF;IADC,KAAK,CAAC,mDAAmD,CAAC;6DACpB;AACS;IAA/C,KAAK,CAAC,uCAAuC,CAAC;uDAAuC;AAGtF;IADC,KAAK,CAAC,qDAAqD,CAAC;+DACpB;AACS;IAAjD,KAAK,CAAC,yCAAyC,CAAC;yDAAyC;AAEpC;IAArD,KAAK,CAAC,6CAA6C,CAAC;wDAAmC;AAC9C;IAAzC,KAAK,CAAC,iCAAiC,CAAC;kDAAkC;AAEvB;IAAnD,KAAK,CAAC,2CAA2C,CAAC;sDAAiC;AAC5C;IAAvC,KAAK,CAAC,+BAA+B,CAAC;gDAAgC;AAEpB;IAAlD,KAAK,CAAC,0CAA0C,CAAC;2DAA4C;AAE/C;IAA9C,KAAK,CAAC,sCAAsC,CAAC;iDAA+B;AAC9D;IAAd,KAAK,CAAC,MAAM,CAAC;yCAAwB;AAEV;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAwB;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAiB;AAlCjC,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAuZvB","sourcesContent":["import { LitElement, html, css, TemplateResult, PropertyValues } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport {\n BillingInfo,\n CustomerInfo,\n DonorContactInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { AutoCompleteFieldOptions } from './autocomplete-field-options';\nimport { SpacerOption } from '../badged-input';\nimport { BadgedInput } from '../badged-input';\nimport '../badged-input';\n\nimport emailImg from '@internetarchive/icon-email/index.js';\nimport localePinImg from '@internetarchive/icon-locale-pin/index.js';\nimport userIcon from '@internetarchive/icon-user/index.js';\n\nimport { countries } from './countries';\n\n@customElement('contact-form')\nexport class ContactForm extends LitElement {\n @query('badged-input.donation-contact-form-email') emailBadgedInput!: BadgedInput;\n @query('#donation-contact-form-email') emailField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-first-name') firstNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-first-name') firstNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-last-name') lastNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-last-name') lastNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-postal-code') postalBadgedInput!: BadgedInput;\n @query('#donation-contact-form-postal-code') postalCodeField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-street-address')\n streetAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-street-address') streetAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-extended-address')\n extendedAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-extended-address') extendedAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-locality') localityBadgedInput!: BadgedInput;\n @query('#donation-contact-form-locality') localityField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-region') regionBadgedInput!: BadgedInput;\n @query('#donation-contact-form-region') regionField!: HTMLInputElement;\n\n @query('#donation-contact-form-countryCodeAlpha2') countryCodeAlpha2Field!: HTMLSelectElement;\n\n @query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;\n @query('form') form!: HTMLFormElement;\n\n @property({ type: String }) selectedCountry = 'US';\n\n @property({ type: String }) donorEmail = '';\n\n updated(changed: PropertyValues): void {\n if (changed.has('donorEmail')) {\n this.emailField.value = this.donorEmail ?? '';\n }\n }\n\n reportValidity(): boolean {\n const fieldBadgedInputs: Array<[HTMLInputElement, BadgedInput]> = [\n [this.emailField, this.emailBadgedInput],\n [this.firstNameField, this.firstNameBadgedInput],\n [this.lastNameField, this.lastNameBadgedInput],\n [this.regionField, this.regionBadgedInput],\n [this.localityField, this.localityBadgedInput],\n [this.streetAddressField, this.streetAddressBadgedInput],\n [this.postalCodeField, this.postalBadgedInput],\n ];\n\n let isValid = true;\n fieldBadgedInputs.forEach(([inputElement, badgedInput]) => {\n const fieldValid = inputElement.checkValidity();\n isValid = isValid && fieldValid;\n if (!fieldValid) {\n badgedInput.error = true;\n }\n });\n\n if (!isValid) {\n this.errorMessage.innerText = 'Please enter any missing or invalid contact information below';\n } else {\n this.errorMessage.innerText = '';\n }\n\n return isValid;\n }\n\n focus(): void {\n this.emailField.focus();\n }\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div id=\"donation-contact-form-error-message\"></div>\n <form>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-email',\n placeholder: 'Email',\n required: true,\n fieldType: 'email',\n name: 'email',\n autocomplete: 'email',\n minlength: 5,\n maxlength: 255,\n icon: emailImg,\n })}\n </div>\n </fieldset>\n\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-first-name',\n placeholder: 'First name',\n name: 'fname',\n required: true,\n validationPattern: '.*\\\\S{2,}.*',\n maxlength: 255,\n autocomplete: 'given-name',\n icon: userIcon,\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-last-name',\n placeholder: 'Last name',\n name: 'lname',\n autocomplete: 'family-name',\n required: true,\n validationPattern: '.*\\\\S{2,}.*',\n maxlength: 255,\n })}\n </div>\n </fieldset>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-street-address',\n placeholder: 'Address Line 1',\n required: true,\n autocomplete: 'address-line1',\n icon: localePinImg,\n name: 'street-address',\n validationPattern: '.*?\\\\S.{2,}\\\\S.*?',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-extended-address',\n placeholder: 'Address Line 2 (optional)',\n autocomplete: 'address-line2',\n required: false,\n name: 'extended-address',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-locality',\n placeholder: 'City',\n autocomplete: 'address-level2',\n required: true,\n name: 'locality',\n validationPattern: '.*\\\\S{2,}.*',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-region',\n placeholder: 'State / Province',\n autocomplete: 'address-level1',\n required: this.regionAndPostalCodeRequired,\n name: 'region',\n validationPattern: '.*\\\\S{2,}.*',\n })}\n ${this.generateInput({\n id: 'donation-contact-form-postal-code',\n placeholder: 'Zip / Postal',\n autocomplete: 'postal-code',\n required: this.regionAndPostalCodeRequired,\n name: 'postal',\n validationPattern: '^\\\\d{5}(-?\\\\d{4})?$',\n iconSpaceOption: SpacerOption.CompressSpace,\n })}\n </div>\n <div class=\"row\">${this.countrySelectorTemplate}</div>\n </fieldset>\n </form>\n ${this.getStyles}\n `;\n }\n\n private get regionAndPostalCodeRequired(): boolean {\n return this.selectedCountry === 'US';\n }\n\n private get countrySelectorTemplate(): TemplateResult {\n return html`\n <badged-input>\n <select\n id=\"donation-contact-form-countryCodeAlpha2\"\n @change=${(e: Event) => {\n const newValue = (e.target as HTMLSelectElement).value;\n if (countries[newValue]) this.selectedCountry = newValue;\n }}\n >\n ${Object.keys(countries).map(key => {\n const name = countries[key];\n return html`\n <option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>\n `;\n })}\n </select>\n </badged-input>\n `;\n }\n\n /** @inheritdoc */\n createRenderRoot(): this {\n // Render template without shadow DOM. Note that shadow DOM features like\n // encapsulated CSS and slots are unavailable.\n // Form autofill does not work properly in the shadow DOM\n // so we need our form fields in the light DOM\n return this;\n }\n\n // reset the error state when the user focuses the input\n private inputFocused(e: KeyboardEvent): void {\n this.errorMessage.innerText = '';\n const input = e.target as HTMLInputElement;\n const inputIdentifier = input.id;\n const badgedInput = this.querySelector(`badged-input.${inputIdentifier}`) as BadgedInput;\n badgedInput.error = false;\n }\n\n private generateInput(options: {\n id: string;\n placeholder: string;\n required?: boolean;\n fieldType?: 'text' | 'email';\n autocomplete?: AutoCompleteFieldOptions;\n minlength?: number;\n maxlength?: number;\n name: string;\n icon?: TemplateResult;\n iconSpaceOption?: SpacerOption;\n validationPattern?: string;\n }): TemplateResult {\n const required = options.required ?? true;\n const fieldType = options.fieldType ?? 'text';\n const iconOption = options.iconSpaceOption ?? SpacerOption.LeaveSpace;\n\n return html`\n <badged-input\n class=${options.id}\n .icon=${options.icon}\n .iconSpaceOption=${iconOption}\n ?required=${options.required}\n >\n <label for=${options.id}>${options.placeholder}</label>\n <input\n type=${fieldType}\n id=${options.id}\n class=\"donation-contact-form-input\"\n name=${options.name}\n aria-label=${options.placeholder}\n placeholder=${options.placeholder}\n maxlength=${ifDefined(options.maxlength)}\n minlength=${ifDefined(options.minlength)}\n autocomplete=${options.autocomplete ?? 'on'}\n pattern=${ifDefined(options.validationPattern)}\n @focus=${this.inputFocused}\n ?required=${required}\n />\n </badged-input>\n `;\n }\n\n get donorContactInfo(): DonorContactInfo {\n return new DonorContactInfo({\n billing: this.billingInfo,\n customer: this.contactInfo,\n });\n }\n\n get billingInfo(): BillingInfo {\n const billingInfo = new BillingInfo({\n streetAddress: this.streetAddressField.value,\n extendedAddress: this.extendedAddressField.value,\n locality: this.localityField.value,\n region: this.regionField.value,\n postalCode: this.postalCodeField.value,\n countryCodeAlpha2: this.countryCodeAlpha2Field.value,\n });\n return billingInfo;\n }\n\n get contactInfo(): CustomerInfo {\n return new CustomerInfo({\n email: this.emailField.value,\n firstName: this.firstNameField.value,\n lastName: this.lastNameField.value,\n });\n }\n\n /**\n * This is not the normal LitElement styles block.\n *\n * This element uses the clear DOM instead of the shadow DOM so it can't use\n * the shadowRoot's isolated styling. This is a bit of a workaround to keep all of\n * the styling local by writing out our own <style> tag and just be careful about\n * the selectors since they will leak outside of this component.\n *\n * @readonly\n * @private\n * @type {TemplateResult}\n * @memberof ContactForm\n */\n private get getStyles(): TemplateResult {\n const noIconSpacerWidth = css`var(--badgedInputNoIconSpacerWidth, 3rem)`;\n const iconSpacerWidth = css`var(--badgedInputIconSpacerWidth, 5rem)`;\n\n const fieldSetSpacing = css`var(--fieldSetSpacing, 1rem)`;\n const fieldFontFamily = css`var(--fontFamily, \"Helvetica Neue\", Helvetica, Arial, sans-serif)`;\n const fieldFontSize = css`var(--contactFieldFontSize, 1.6rem)`;\n const fieldFontColor = css`var(--inputFieldFontColor, #333)`;\n\n const iconFieldWidth = css`calc(100% - ${iconSpacerWidth})`;\n const noIconFieldWidth = css`calc(100% - ${noIconSpacerWidth})`;\n\n return html`\n <style>\n /*\n **NOTE**\n This element is in the lightDOM so be sure to prefix all styles\n with \"contact-form\" so styles don't leak.\n */\n contact-form fieldset {\n border: 0;\n padding: 0;\n margin: 0;\n margin-bottom: ${fieldSetSpacing};\n background-color: white;\n }\n\n /* These 1px and 0 margins in the next few selectors are to account for the\n double outlines caused by the fields being right next to each other */\n contact-form .row {\n display: flex;\n margin: -1px 0 0 0;\n }\n\n contact-form fieldset .row:first-child {\n margin-top: 0;\n }\n\n contact-form badged-input.donation-contact-form-region {\n width: 60%;\n }\n\n contact-form badged-input.donation-contact-form-postal-code {\n width: 40%;\n }\n\n contact-form #donation-contact-form-region {\n width: ${iconFieldWidth};\n }\n\n contact-form #donation-contact-form-postal-code {\n width: ${noIconFieldWidth};\n }\n\n contact-form #donation-contact-form-error-message {\n color: red;\n font-size: 1.4rem;\n margin-bottom: 0.6rem;\n }\n\n contact-form #donation-contact-form-last-name {\n width: ${noIconFieldWidth};\n }\n\n /* only show for screen readers */\n contact-form label {\n position: absolute;\n left: -10000px;\n top: auto;\n width: 1px;\n height: 1px;\n overflow: hidden;\n }\n\n contact-form .donation-contact-form-input {\n width: ${iconFieldWidth};\n border: 0;\n outline: 0;\n background: transparent;\n font-weight: bold;\n color: ${fieldFontColor};\n font-size: ${fieldFontSize};\n padding: 0;\n font-family: ${fieldFontFamily};\n }\n\n contact-form .donation-contact-form-input::placeholder {\n color: revert;\n }\n\n contact-form #donation-contact-form-countryCodeAlpha2 {\n width: calc(100%);\n height: 100%;\n box-sizing: border-box;\n font-weight: bold;\n font-size: ${fieldFontSize};\n font-family: ${fieldFontFamily};\n border: 0;\n background: #fff;\n }\n </style>\n `;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"contact-form.js","sourceRoot":"","sources":["../../../../src/form-elements/contact-form/contact-form.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAkC,MAAM,KAAK,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,gBAAgB,GACjB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,iBAAiB,CAAC;AAEzB,OAAO,QAAQ,MAAM,sCAAsC,CAAC;AAC5D,OAAO,YAAY,MAAM,2CAA2C,CAAC;AACrE,OAAO,QAAQ,MAAM,qCAAqC,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAG7B,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAApC;;QAgCL,uBAAuB;QACK,oBAAe,GAAG,IAAI,CAAC;QAEvB,eAAU,GAAG,EAAE,CAAC;QAoD5C,wCAAwC;QAChC,sBAAiB,GAAG,aAAa,CAAC;QAClC,gCAA2B,GAAG,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAE3E,sFAAsF;QAC9E,yBAAoB,GAAG,mBAAmB,CAAC;QAC3C,mCAA8B,GAAG,GAAG,CAAC,gCAAgC,CAAC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} from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport {\n BillingInfo,\n CustomerInfo,\n DonorContactInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { AutoCompleteFieldOptions } from './autocomplete-field-options';\nimport { SpacerOption } from '../badged-input';\nimport { BadgedInput } from '../badged-input';\nimport '../badged-input';\n\nimport emailImg from '@internetarchive/icon-email/index.js';\nimport localePinImg from '@internetarchive/icon-locale-pin/index.js';\nimport userIcon from '@internetarchive/icon-user/index.js';\n\nimport { countries } from './countries';\nimport { msg } from '@lit/localize';\n\n@customElement('contact-form')\nexport class ContactForm extends LitElement {\n @query('badged-input.donation-contact-form-email') emailBadgedInput!: BadgedInput;\n @query('#donation-contact-form-email') emailField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-first-name') firstNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-first-name') firstNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-last-name') lastNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-last-name') lastNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-postal-code') postalBadgedInput!: BadgedInput;\n @query('#donation-contact-form-postal-code') postalCodeField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-street-address')\n streetAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-street-address') streetAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-extended-address')\n extendedAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-extended-address') extendedAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-locality') localityBadgedInput!: BadgedInput;\n @query('#donation-contact-form-locality') localityField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-region') regionBadgedInput!: BadgedInput;\n @query('#donation-contact-form-region') regionField!: HTMLInputElement;\n\n @query('#donation-contact-form-countryCodeAlpha2') countryCodeAlpha2Field!: HTMLSelectElement;\n\n @query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;\n @query('form') form!: HTMLFormElement;\n\n /** @keyof countries */\n @property({ type: String }) selectedCountry = 'US';\n\n @property({ type: String }) donorEmail = '';\n\n updated(changed: PropertyValues): void {\n if (changed.has('donorEmail')) {\n this.emailField.value = this.donorEmail ?? '';\n }\n }\n\n reportValidity(): boolean {\n this.validateFormFields();\n return this.validateForm();\n }\n\n // validate each field and set the error state on the badged-inputs\n private validateFormFields(): void {\n const fields: {\n badgedInput: BadgedInput;\n inputField: HTMLInputElement;\n }[] = [\n { badgedInput: this.emailBadgedInput, inputField: this.emailField },\n { badgedInput: this.firstNameBadgedInput, inputField: this.firstNameField },\n { badgedInput: this.lastNameBadgedInput, inputField: this.lastNameField },\n { badgedInput: this.streetAddressBadgedInput, inputField: this.streetAddressField },\n { badgedInput: this.extendedAddressBadgedInput, inputField: this.extendedAddressField },\n { badgedInput: this.localityBadgedInput, inputField: this.localityField },\n { badgedInput: this.regionBadgedInput, inputField: this.regionField },\n { badgedInput: this.postalBadgedInput, inputField: this.postalCodeField },\n ];\n fields.forEach(({ badgedInput, inputField }) => {\n badgedInput.error = !inputField.checkValidity();\n });\n }\n\n // validate the overall form and show error messages\n private validateForm(): boolean {\n const isValid = this.form.reportValidity();\n\n if (!isValid) {\n this.errorMessage.innerText = msg(\n 'Please enter any missing or invalid contact information below',\n );\n } else {\n this.errorMessage.innerText = '';\n }\n\n return isValid;\n }\n\n focus(): void {\n this.emailField.focus();\n }\n\n // minimum two non-whitespace characters\n private minTwoCharPattern = '.*\\\\S{2,}.*';\n private minTwoCharValidationMessage = msg('Enter at least two characters');\n\n // at least two non-whitespace characters with at least two characters in between them\n private streetAddressPattern = '.*?\\\\S.{2,}\\\\S.*?';\n private streetAddressValidationMessage = msg('Enter at least four characters');\n\n // matches 12345 or 12345-6789 or 123456789\n private zipCodePattern = '^\\\\d{5}(-?\\\\d{4})?$';\n private zipCodeValidationMessage = msg('Enter a valid 5 or 9 digit zip/postal code');\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div id=\"donation-contact-form-error-message\"></div>\n <form>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-email',\n placeholder: 'Email',\n required: true,\n fieldType: 'email',\n name: 'email',\n autocomplete: 'email',\n minlength: 5,\n maxlength: 255,\n icon: emailImg,\n })}\n </div>\n </fieldset>\n\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-first-name',\n placeholder: 'First name',\n name: 'fname',\n required: true,\n validationPattern: this.minTwoCharPattern,\n validationMessage: this.minTwoCharValidationMessage,\n maxlength: 255,\n autocomplete: 'given-name',\n icon: userIcon,\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-last-name',\n placeholder: 'Last name',\n name: 'lname',\n autocomplete: 'family-name',\n required: true,\n validationPattern: this.minTwoCharPattern,\n validationMessage: this.minTwoCharValidationMessage,\n maxlength: 255,\n })}\n </div>\n </fieldset>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-street-address',\n placeholder: 'Address Line 1',\n required: true,\n autocomplete: 'address-line1',\n icon: localePinImg,\n name: 'street-address',\n validationPattern: this.streetAddressPattern,\n validationMessage: this.streetAddressValidationMessage,\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-extended-address',\n placeholder: 'Address Line 2 (optional)',\n autocomplete: 'address-line2',\n required: false,\n name: 'extended-address',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-locality',\n placeholder: 'City',\n autocomplete: 'address-level2',\n required: true,\n name: 'locality',\n validationPattern: this.minTwoCharPattern,\n validationMessage: this.minTwoCharValidationMessage,\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-region',\n placeholder: 'State / Province',\n autocomplete: 'address-level1',\n required: this.regionAndPostalCodeRequired,\n name: 'region',\n validationPattern: this.minTwoCharPattern,\n validationMessage: this.minTwoCharValidationMessage,\n })}\n ${this.generateInput({\n id: 'donation-contact-form-postal-code',\n placeholder: 'Zip / Postal',\n autocomplete: 'postal-code',\n required: this.regionAndPostalCodeRequired,\n name: 'postal',\n validationPattern: this.zipCodePattern,\n validationMessage: this.zipCodeValidationMessage,\n iconSpaceOption: SpacerOption.CompressSpace,\n })}\n </div>\n <div class=\"row\">${this.countrySelectorTemplate}</div>\n </fieldset>\n </form>\n ${this.getStyles}\n `;\n }\n\n private get regionAndPostalCodeRequired(): boolean {\n return this.selectedCountry === 'US';\n }\n\n private get countrySelectorTemplate(): TemplateResult {\n return html`\n <badged-input>\n <select\n id=\"donation-contact-form-countryCodeAlpha2\"\n @change=${(e: Event) => {\n const newValue = (e.target as HTMLSelectElement).value;\n if (countries[newValue]) this.selectedCountry = newValue;\n }}\n >\n ${Object.keys(countries).map(key => {\n const name = countries[key];\n return html`\n <option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>\n `;\n })}\n </select>\n </badged-input>\n `;\n }\n\n /** @inheritdoc */\n createRenderRoot(): this {\n // Render template without shadow DOM. Note that shadow DOM features like\n // encapsulated CSS and slots are unavailable.\n // Form autofill does not work properly in the shadow DOM\n // so we need our form fields in the light DOM\n return this;\n }\n\n // reset the error state when the user focuses the input\n private inputFocused(e: KeyboardEvent): void {\n this.errorMessage.innerText = '';\n const input = e.target as HTMLInputElement;\n const inputIdentifier = input.id;\n const badgedInput = this.querySelector(`badged-input.${inputIdentifier}`) as BadgedInput;\n badgedInput.error = false;\n }\n\n private generateInput(options: {\n id: string;\n placeholder: string;\n required?: boolean;\n fieldType?: 'text' | 'email';\n autocomplete?: AutoCompleteFieldOptions;\n minlength?: number;\n maxlength?: number;\n name: string;\n icon?: TemplateResult;\n iconSpaceOption?: SpacerOption;\n validationPattern?: string;\n validationMessage?: string;\n }): TemplateResult {\n const required = options.required ?? true;\n const fieldType = options.fieldType ?? 'text';\n const iconOption = options.iconSpaceOption ?? SpacerOption.LeaveSpace;\n\n return html`\n <badged-input\n class=${options.id}\n .icon=${options.icon}\n .iconSpaceOption=${iconOption}\n ?required=${options.required}\n >\n <label for=${options.id}>${options.placeholder}</label>\n <input\n type=${fieldType}\n id=${options.id}\n class=\"donation-contact-form-input\"\n name=${options.name}\n aria-label=${options.placeholder}\n placeholder=${options.placeholder}\n maxlength=${ifDefined(options.maxlength)}\n minlength=${ifDefined(options.minlength)}\n autocomplete=${options.autocomplete ?? 'on'}\n pattern=${ifDefined(options.validationPattern)}\n title=${ifDefined(options.validationMessage)}\n @focus=${this.inputFocused}\n ?required=${required}\n />\n </badged-input>\n `;\n }\n\n get donorContactInfo(): DonorContactInfo {\n return new DonorContactInfo({\n billing: this.billingInfo,\n customer: this.contactInfo,\n });\n }\n\n get billingInfo(): BillingInfo {\n const billingInfo = new BillingInfo({\n streetAddress: this.streetAddressField.value,\n extendedAddress: this.extendedAddressField.value,\n locality: this.localityField.value,\n region: this.regionField.value,\n postalCode: this.postalCodeField.value,\n countryCodeAlpha2: this.countryCodeAlpha2Field.value,\n });\n return billingInfo;\n }\n\n get contactInfo(): CustomerInfo {\n return new CustomerInfo({\n email: this.emailField.value,\n firstName: this.firstNameField.value,\n lastName: this.lastNameField.value,\n });\n }\n\n /**\n * This is not the normal LitElement styles block.\n *\n * This element uses the clear DOM instead of the shadow DOM so it can't use\n * the shadowRoot's isolated styling. This is a bit of a workaround to keep all of\n * the styling local by writing out our own <style> tag and just be careful about\n * the selectors since they will leak outside of this component.\n *\n * @readonly\n * @private\n * @type {TemplateResult}\n * @memberof ContactForm\n */\n private get getStyles(): TemplateResult {\n const noIconSpacerWidth = css`var(--badgedInputNoIconSpacerWidth, 3rem)`;\n const iconSpacerWidth = css`var(--badgedInputIconSpacerWidth, 5rem)`;\n\n const fieldSetSpacing = css`var(--fieldSetSpacing, 1rem)`;\n const fieldFontFamily = css`var(--fontFamily, \"Helvetica Neue\", Helvetica, Arial, sans-serif)`;\n const fieldFontSize = css`var(--contactFieldFontSize, 1.6rem)`;\n const fieldFontColor = css`var(--inputFieldFontColor, #333)`;\n\n const iconFieldWidth = css`calc(100% - ${iconSpacerWidth})`;\n const noIconFieldWidth = css`calc(100% - ${noIconSpacerWidth})`;\n\n return html`\n <style>\n /*\n **NOTE**\n This element is in the lightDOM so be sure to prefix all styles\n with \"contact-form\" so styles don't leak.\n */\n contact-form fieldset {\n border: 0;\n padding: 0;\n margin: 0;\n margin-bottom: ${fieldSetSpacing};\n background-color: white;\n }\n\n /* These 1px and 0 margins in the next few selectors are to account for the\n double outlines caused by the fields being right next to each other */\n contact-form .row {\n display: flex;\n margin: -1px 0 0 0;\n }\n\n contact-form fieldset .row:first-child {\n margin-top: 0;\n }\n\n contact-form badged-input.donation-contact-form-region {\n width: 60%;\n }\n\n contact-form badged-input.donation-contact-form-postal-code {\n width: 40%;\n }\n\n contact-form #donation-contact-form-region {\n width: ${iconFieldWidth};\n }\n\n contact-form #donation-contact-form-postal-code {\n width: ${noIconFieldWidth};\n }\n\n contact-form #donation-contact-form-error-message {\n color: red;\n font-size: 1.4rem;\n margin-bottom: 0.6rem;\n }\n\n contact-form #donation-contact-form-last-name {\n width: ${noIconFieldWidth};\n }\n\n /* only show for screen readers */\n contact-form label {\n position: absolute;\n left: -10000px;\n top: auto;\n width: 1px;\n height: 1px;\n overflow: hidden;\n }\n\n contact-form .donation-contact-form-input {\n width: ${iconFieldWidth};\n border: 0;\n outline: 0;\n background: transparent;\n font-weight: bold;\n color: ${fieldFontColor};\n font-size: ${fieldFontSize};\n padding: 0;\n font-family: ${fieldFontFamily};\n }\n\n contact-form .donation-contact-form-input::placeholder {\n color: revert;\n }\n\n contact-form #donation-contact-form-countryCodeAlpha2 {\n width: calc(100%);\n height: 100%;\n box-sizing: border-box;\n font-weight: bold;\n font-size: ${fieldFontSize};\n font-family: ${fieldFontFamily};\n border: 0;\n background: #fff;\n }\n </style>\n `;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/donation-form",
|
|
3
|
-
"version": "1.0.3
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "The Internet Archive Donation Form",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@internetarchive/lazy-loader-service": "^0.2.0",
|
|
47
47
|
"@internetarchive/modal-manager": "^2.0.0",
|
|
48
48
|
"@internetarchive/promised-singleton": "^0.2.1",
|
|
49
|
+
"@lit/localize": "^0.12.2",
|
|
49
50
|
"currency.js": "^2.0.2",
|
|
50
51
|
"lit": "^2.8.0",
|
|
51
52
|
"nanoevents": "^9.1.0"
|
|
@@ -17,6 +17,7 @@ import localePinImg from '@internetarchive/icon-locale-pin/index.js';
|
|
|
17
17
|
import userIcon from '@internetarchive/icon-user/index.js';
|
|
18
18
|
|
|
19
19
|
import { countries } from './countries';
|
|
20
|
+
import { msg } from '@lit/localize';
|
|
20
21
|
|
|
21
22
|
@customElement('contact-form')
|
|
22
23
|
export class ContactForm extends LitElement {
|
|
@@ -51,6 +52,7 @@ export class ContactForm extends LitElement {
|
|
|
51
52
|
@query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;
|
|
52
53
|
@query('form') form!: HTMLFormElement;
|
|
53
54
|
|
|
55
|
+
/** @keyof countries */
|
|
54
56
|
@property({ type: String }) selectedCountry = 'US';
|
|
55
57
|
|
|
56
58
|
@property({ type: String }) donorEmail = '';
|
|
@@ -62,27 +64,38 @@ export class ContactForm extends LitElement {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
reportValidity(): boolean {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
[this.lastNameField, this.lastNameBadgedInput],
|
|
69
|
-
[this.regionField, this.regionBadgedInput],
|
|
70
|
-
[this.localityField, this.localityBadgedInput],
|
|
71
|
-
[this.streetAddressField, this.streetAddressBadgedInput],
|
|
72
|
-
[this.postalCodeField, this.postalBadgedInput],
|
|
73
|
-
];
|
|
67
|
+
this.validateFormFields();
|
|
68
|
+
return this.validateForm();
|
|
69
|
+
}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
71
|
+
// validate each field and set the error state on the badged-inputs
|
|
72
|
+
private validateFormFields(): void {
|
|
73
|
+
const fields: {
|
|
74
|
+
badgedInput: BadgedInput;
|
|
75
|
+
inputField: HTMLInputElement;
|
|
76
|
+
}[] = [
|
|
77
|
+
{ badgedInput: this.emailBadgedInput, inputField: this.emailField },
|
|
78
|
+
{ badgedInput: this.firstNameBadgedInput, inputField: this.firstNameField },
|
|
79
|
+
{ badgedInput: this.lastNameBadgedInput, inputField: this.lastNameField },
|
|
80
|
+
{ badgedInput: this.streetAddressBadgedInput, inputField: this.streetAddressField },
|
|
81
|
+
{ badgedInput: this.extendedAddressBadgedInput, inputField: this.extendedAddressField },
|
|
82
|
+
{ badgedInput: this.localityBadgedInput, inputField: this.localityField },
|
|
83
|
+
{ badgedInput: this.regionBadgedInput, inputField: this.regionField },
|
|
84
|
+
{ badgedInput: this.postalBadgedInput, inputField: this.postalCodeField },
|
|
85
|
+
];
|
|
86
|
+
fields.forEach(({ badgedInput, inputField }) => {
|
|
87
|
+
badgedInput.error = !inputField.checkValidity();
|
|
82
88
|
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// validate the overall form and show error messages
|
|
92
|
+
private validateForm(): boolean {
|
|
93
|
+
const isValid = this.form.reportValidity();
|
|
83
94
|
|
|
84
95
|
if (!isValid) {
|
|
85
|
-
this.errorMessage.innerText =
|
|
96
|
+
this.errorMessage.innerText = msg(
|
|
97
|
+
'Please enter any missing or invalid contact information below',
|
|
98
|
+
);
|
|
86
99
|
} else {
|
|
87
100
|
this.errorMessage.innerText = '';
|
|
88
101
|
}
|
|
@@ -94,6 +107,18 @@ export class ContactForm extends LitElement {
|
|
|
94
107
|
this.emailField.focus();
|
|
95
108
|
}
|
|
96
109
|
|
|
110
|
+
// minimum two non-whitespace characters
|
|
111
|
+
private minTwoCharPattern = '.*\\S{2,}.*';
|
|
112
|
+
private minTwoCharValidationMessage = msg('Enter at least two characters');
|
|
113
|
+
|
|
114
|
+
// at least two non-whitespace characters with at least two characters in between them
|
|
115
|
+
private streetAddressPattern = '.*?\\S.{2,}\\S.*?';
|
|
116
|
+
private streetAddressValidationMessage = msg('Enter at least four characters');
|
|
117
|
+
|
|
118
|
+
// matches 12345 or 12345-6789 or 123456789
|
|
119
|
+
private zipCodePattern = '^\\d{5}(-?\\d{4})?$';
|
|
120
|
+
private zipCodeValidationMessage = msg('Enter a valid 5 or 9 digit zip/postal code');
|
|
121
|
+
|
|
97
122
|
/** @inheritdoc */
|
|
98
123
|
render(): TemplateResult {
|
|
99
124
|
return html`
|
|
@@ -122,7 +147,8 @@ export class ContactForm extends LitElement {
|
|
|
122
147
|
placeholder: 'First name',
|
|
123
148
|
name: 'fname',
|
|
124
149
|
required: true,
|
|
125
|
-
validationPattern:
|
|
150
|
+
validationPattern: this.minTwoCharPattern,
|
|
151
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
126
152
|
maxlength: 255,
|
|
127
153
|
autocomplete: 'given-name',
|
|
128
154
|
icon: userIcon,
|
|
@@ -135,7 +161,8 @@ export class ContactForm extends LitElement {
|
|
|
135
161
|
name: 'lname',
|
|
136
162
|
autocomplete: 'family-name',
|
|
137
163
|
required: true,
|
|
138
|
-
validationPattern:
|
|
164
|
+
validationPattern: this.minTwoCharPattern,
|
|
165
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
139
166
|
maxlength: 255,
|
|
140
167
|
})}
|
|
141
168
|
</div>
|
|
@@ -149,7 +176,8 @@ export class ContactForm extends LitElement {
|
|
|
149
176
|
autocomplete: 'address-line1',
|
|
150
177
|
icon: localePinImg,
|
|
151
178
|
name: 'street-address',
|
|
152
|
-
validationPattern:
|
|
179
|
+
validationPattern: this.streetAddressPattern,
|
|
180
|
+
validationMessage: this.streetAddressValidationMessage,
|
|
153
181
|
})}
|
|
154
182
|
</div>
|
|
155
183
|
<div class="row">
|
|
@@ -168,7 +196,8 @@ export class ContactForm extends LitElement {
|
|
|
168
196
|
autocomplete: 'address-level2',
|
|
169
197
|
required: true,
|
|
170
198
|
name: 'locality',
|
|
171
|
-
validationPattern:
|
|
199
|
+
validationPattern: this.minTwoCharPattern,
|
|
200
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
172
201
|
})}
|
|
173
202
|
</div>
|
|
174
203
|
<div class="row">
|
|
@@ -178,7 +207,8 @@ export class ContactForm extends LitElement {
|
|
|
178
207
|
autocomplete: 'address-level1',
|
|
179
208
|
required: this.regionAndPostalCodeRequired,
|
|
180
209
|
name: 'region',
|
|
181
|
-
validationPattern:
|
|
210
|
+
validationPattern: this.minTwoCharPattern,
|
|
211
|
+
validationMessage: this.minTwoCharValidationMessage,
|
|
182
212
|
})}
|
|
183
213
|
${this.generateInput({
|
|
184
214
|
id: 'donation-contact-form-postal-code',
|
|
@@ -186,7 +216,8 @@ export class ContactForm extends LitElement {
|
|
|
186
216
|
autocomplete: 'postal-code',
|
|
187
217
|
required: this.regionAndPostalCodeRequired,
|
|
188
218
|
name: 'postal',
|
|
189
|
-
validationPattern:
|
|
219
|
+
validationPattern: this.zipCodePattern,
|
|
220
|
+
validationMessage: this.zipCodeValidationMessage,
|
|
190
221
|
iconSpaceOption: SpacerOption.CompressSpace,
|
|
191
222
|
})}
|
|
192
223
|
</div>
|
|
@@ -252,6 +283,7 @@ export class ContactForm extends LitElement {
|
|
|
252
283
|
icon?: TemplateResult;
|
|
253
284
|
iconSpaceOption?: SpacerOption;
|
|
254
285
|
validationPattern?: string;
|
|
286
|
+
validationMessage?: string;
|
|
255
287
|
}): TemplateResult {
|
|
256
288
|
const required = options.required ?? true;
|
|
257
289
|
const fieldType = options.fieldType ?? 'text';
|
|
@@ -276,6 +308,7 @@ export class ContactForm extends LitElement {
|
|
|
276
308
|
minlength=${ifDefined(options.minlength)}
|
|
277
309
|
autocomplete=${options.autocomplete ?? 'on'}
|
|
278
310
|
pattern=${ifDefined(options.validationPattern)}
|
|
311
|
+
title=${ifDefined(options.validationMessage)}
|
|
279
312
|
@focus=${this.inputFocused}
|
|
280
313
|
?required=${required}
|
|
281
314
|
/>
|