@progressive-development/pd-forms 0.0.41 → 0.0.43

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.41",
6
+ "version": "0.0.43",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -19,6 +19,7 @@ export class PdBaseUIInput extends PdBaseUI {
19
19
  disabled: { type: Boolean }, // disabled flag for element
20
20
  readonly: { type: Boolean }, // readonly flag for element
21
21
  required: { type: Boolean }, // required flag for element
22
+ requiredMsg: { type: String }, // specific error msg for required field
22
23
  valueName: { type: String },
23
24
  defaultRequiredChar: { type: String },
24
25
  defaultValue: { type: String }, // default value for input element (used for reset) TODO: Das hier ggf. automatisch mit erstem gesetzten Wert füllen?
@@ -59,11 +59,11 @@ export class PdFormContainer extends LitElement {
59
59
 
60
60
  _validateForm(e) {
61
61
 
62
- // validate required fields
62
+ // validate required fields TODO: Auf PdInputxxx beschränken
63
63
  this.querySelectorAll("[required]").forEach(el => {
64
64
  const tmpEl = el;
65
65
  if (!el.value || el.value === "") {
66
- tmpEl.errorMsg = "Field is required";
66
+ tmpEl.errorMsg = el.requiredMsg || "Field is required"; // TODO: msg required field local
67
67
  e.detail.errorMap.set(el.id, tmpEl.errorMsg);
68
68
  } else {
69
69
  tmpEl.errorMsg = "";
@@ -71,15 +71,15 @@ export class PdFormContainer extends LitElement {
71
71
  })
72
72
 
73
73
  // general validate method
74
- const validateByType = (fieldType, validFunc) => {
74
+ const validateByType = (fieldType, validFunc, example) => {
75
75
  this.querySelectorAll(`[field-type=${fieldType}]`).forEach(el => {
76
76
  const tmpEl = el;
77
- // if not already added ass required field
77
+ // if not already added as required field
78
78
  if (!e.detail.errorMap.has(el.id) && el.value && el.value.length > 0) {
79
79
  if (validFunc(el.value)) {
80
80
  tmpEl.errorMsg = "";
81
81
  } else {
82
- tmpEl.errorMsg = `Invalid ${fieldType} format`;
82
+ tmpEl.errorMsg = `Format ${example ? `${example} required` : "invalid"}`;
83
83
  e.detail.errorMap.set(el.id, tmpEl.errorMsg);
84
84
  }
85
85
  }
@@ -87,8 +87,10 @@ export class PdFormContainer extends LitElement {
87
87
  };
88
88
 
89
89
  // validate mail and phone inputs
90
- validateByType("mail", PdFormContainer._mailIsValid);
91
- validateByType("phone", PdFormContainer._phoneIsValid);
90
+ validateByType("mail", PdFormContainer._mailIsValid, "mail@example.com");
91
+ validateByType("phone", PdFormContainer._phoneIsValid, "+32 494 667085");
92
+ validateByType("vat", PdFormContainer._vatIsValid, "BE0123456789");
93
+ validateByType("number", (val) => !Number.isNaN(val), "only numbers");
92
94
  }
93
95
 
94
96
  static _mailIsValid(email) {