@progressive-development/pd-contact 0.1.43 → 0.1.45

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Progressive Development Contact component",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.1.43",
6
+ "version": "0.1.45",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
package/src/PdContact.js CHANGED
@@ -85,12 +85,33 @@
85
85
  this._errorMap = new Map();
86
86
  }
87
87
 
88
+ connectedCallback() {
89
+ super.connectedCallback();
90
+ // add validation event listener
91
+ this.addEventListener('validate-form', this._validateForm);
92
+ }
93
+
94
+ disconnectedCallback() {
95
+ super.connectedCallback();
96
+ // add validation event listener
97
+ this.removeEventListener('validate-form', this._validateForm);
98
+ }
99
+
88
100
  firstUpdated() {
89
101
  this.addEventListener('key-pressed', e => {
90
102
  this._errorMap.set(e.detail.name, '');
91
103
  super.requestUpdate();
92
104
  });
93
- this.addEventListener('validate-form', this._validateForm);
105
+
106
+ // first validation if form is already filled (edit)
107
+ if (this.contact) {
108
+ const detail = {
109
+ errorMap: new Map()
110
+ }
111
+ this.shadowRoot?.getElementById("contactContainerId")?.dispatchEvent(
112
+ new CustomEvent("validate-form", {detail})
113
+ );
114
+ }
94
115
  }
95
116
 
96
117
  render() {
@@ -109,13 +130,14 @@
109
130
  class="quarter4"
110
131
  label="Type"
111
132
  required
133
+ value="${this._getRadioValue()}"
112
134
  @field-change="${this._switchAddressType}"
113
135
  style="--group-gap: 20px;"
114
136
  >
115
- <pd-checkbox value="true" valueName="private"
137
+ <pd-checkbox value="${this.contact ? !this.contact.business : true}" valueName="private"
116
138
  >Particulier</pd-checkbox
117
139
  >
118
- <pd-checkbox valueName="business">Onderneming</pd-checkbox>
140
+ <pd-checkbox valueName="business" value="${this.contact ? this.contact.business : false}">Onderneming</pd-checkbox>
119
141
  </pd-radio-group>
120
142
  </pd-form-row>
121
143
 
@@ -252,6 +274,13 @@
252
274
  `;
253
275
  }
254
276
 
277
+ _getRadioValue() {
278
+ if (this.contact) {
279
+ return this.contact.business ? "business" : "private";
280
+ }
281
+ return "private";
282
+ }
283
+
255
284
  _renderViewContact() {
256
285
  return html`
257
286
  <address>
@@ -406,7 +435,7 @@
406
435
  );
407
436
 
408
437
  // set prepared form, if no validation error occured
409
- if (e.detail.errorMap.size === 0) {
438
+ if (e.detail.errorMap.size === 0 && e.detail.formData) {
410
439
  e.detail.formData[this.id] = this._setFormData();
411
440
  }
412
441
  }
@@ -4,8 +4,7 @@ import '../pd-contact.js';
4
4
  export default {
5
5
  title: 'PdContact/Contact',
6
6
  component: 'pd-contact',
7
- argTypes: {
8
-
7
+ argTypes: {
9
8
  },
10
9
  };
11
10
 
@@ -16,17 +15,18 @@ function Template() {
16
15
  `;
17
16
  }
18
17
 
19
- function TemplateView() {
18
+ function TemplateView({summary}) {
19
+ console.log(summary);
20
20
  return html`
21
21
  <h3>View Contact</h3>
22
- <pd-contact summary .contact="${{
22
+ <pd-contact ?summary="${summary}" .contact="${{
23
23
  firstName: 'Peter',
24
24
  lastName: 'Musterman',
25
25
  street: 'Musterstrasse',
26
26
  streetNr: '23b',
27
27
  zip: '9040',
28
28
  city: 'Gent',
29
- phone: '0221/9923443',
29
+ phone1: '0221 992344234',
30
30
  mobil: '0175/9923443',
31
31
  email: 'peter@muster.be'
32
32
  }}"></pd-contact>`;
@@ -38,4 +38,10 @@ ContactForm.args = {
38
38
 
39
39
  export const ContactView = TemplateView.bind({});
40
40
  ContactView.args = {
41
+ summary: "true"
42
+ };
43
+
44
+ export const ContactPreparedForm = TemplateView.bind({});
45
+ ContactView.args = {
46
+ summary: "false"
41
47
  };