@progressive-development/pd-forms 0.0.46 → 0.0.48

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": "Webcomponent pd-forms following open-wc recommendations",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.0.46",
6
+ "version": "0.0.48",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -59,8 +59,11 @@ export class PdFormContainer extends LitElement {
59
59
 
60
60
  _validateForm(e) {
61
61
 
62
+ const reqEl = e.detail.singleElement ? [e.detail.singleElement] :
63
+ this.querySelectorAll("[required]");
64
+
62
65
  // validate required fields TODO: Auf PdInputxxx beschränken
63
- this.querySelectorAll("[required]").forEach(el => {
66
+ reqEl.forEach(el => {
64
67
  const tmpEl = el;
65
68
  if (!el.value || el.value === "") {
66
69
  tmpEl.errorMsg = el.requiredMsg || "Field is required"; // TODO: msg required field local
@@ -72,7 +75,16 @@ export class PdFormContainer extends LitElement {
72
75
 
73
76
  // general validate method
74
77
  const validateByType = (fieldType, validFunc, example) => {
75
- this.querySelectorAll(`[field-type=${fieldType}]`).forEach(el => {
78
+
79
+ if (e.detail.singleElement &&
80
+ e.detail.singleElement.getAttribute("field-type") !== fieldType) {
81
+ return;
82
+ }
83
+
84
+ const reqSpecEl = e.detail.singleElement ? [e.detail.singleElement] :
85
+ this.querySelectorAll(`[field-type=${fieldType}]`);
86
+
87
+ reqSpecEl.forEach(el => {
76
88
  const tmpEl = el;
77
89
  // if not already added as required field
78
90
  if (!e.detail.errorMap.has(el.id) && el.value && el.value.length > 0) {
@@ -91,6 +103,10 @@ export class PdFormContainer extends LitElement {
91
103
  validateByType("phone", PdFormContainer._phoneIsValid, "+32 494 667085");
92
104
  validateByType("vat", PdFormContainer._vatIsValid, "BE0123456789");
93
105
  validateByType("number", (val) => !Number.isNaN(val), "only numbers");
106
+
107
+ if (e.detail.singleElement) {
108
+ e.stopPropagation();
109
+ }
94
110
  }
95
111
 
96
112
  static _mailIsValid(email) {
package/src/PdInput.js CHANGED
@@ -145,7 +145,8 @@ export class PdInput extends PdBaseUIInput {
145
145
  this.value = this._input.value;
146
146
 
147
147
  // If Enter key pressed, fire 'enter-pressed'
148
- if (Number(event.keyCode) === 13) {
148
+ const eventKeyCodeNumber = Number(event.keyCode);
149
+ if (eventKeyCodeNumber === 13) {
149
150
  this.dispatchEvent(
150
151
  new CustomEvent('enter-pressed', {
151
152
  detail: {
@@ -156,7 +157,7 @@ export class PdInput extends PdBaseUIInput {
156
157
  })
157
158
  );
158
159
  event.preventDefault();
159
- } else {
160
+ } else if (eventKeyCodeNumber !== 9) {
160
161
  // If any other key, fire 'key-pressed'
161
162
 
162
163
  // Interessante Stelle, die error msg wird von außen gesetzt
@@ -174,7 +175,18 @@ export class PdInput extends PdBaseUIInput {
174
175
 
175
176
  Nachtrag: Nun auf interne propertie umgestellt, im Test...
176
177
  */
177
- this.errorMsg = '';
178
+ if (this.errorMsg.length > 0) {
179
+ this.dispatchEvent(
180
+ new CustomEvent('validate-form', {
181
+ detail: {
182
+ singleElement: this,
183
+ errorMap: new Map()
184
+ },
185
+ composed: true,
186
+ bubbles: true,
187
+ })
188
+ );
189
+ }
178
190
 
179
191
  this.dispatchEvent(
180
192
  new CustomEvent('key-pressed', {