@rxdi/forms 0.7.210 → 0.7.211

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.
@@ -27,12 +27,12 @@ class FormGroup {
27
27
  this.setFormElement(this.querySelectForm(this.parentElement.shadowRoot || this.parentElement)).setInputs(this.mapEventToInputs(this.querySelectorAllInputs()));
28
28
  }
29
29
  prepareValues() {
30
- Object.keys(this.value).forEach(v => {
30
+ Object.keys(this.value).forEach((v) => {
31
31
  const value = this.value[v];
32
32
  this.errors[v] = this.errors[v] || {};
33
33
  if (value.constructor === Array) {
34
34
  if (value[1] && value[1].constructor === Array) {
35
- value[1].forEach(val => {
35
+ value[1].forEach((val) => {
36
36
  const oldValidators = this.validators.get(v) || [];
37
37
  this.validators.set(v, [...oldValidators, val]);
38
38
  });
@@ -69,15 +69,14 @@ class FormGroup {
69
69
  updateValueAndValidity() {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
71
  this.resetErrors();
72
- const inputs = yield Promise.all(this.querySelectorAllInputs()
73
- .map((i) => __awaiter(this, void 0, void 0, function* () {
72
+ const inputs = yield Promise.all(this.querySelectorAllInputs().map((i) => __awaiter(this, void 0, void 0, function* () {
74
73
  i.setCustomValidity('');
75
74
  this.setElementValidity(i);
76
75
  this.setElementDirty(i);
77
76
  return yield this.validate(i);
78
77
  })));
79
78
  this.getParentElement().requestUpdate();
80
- return inputs.filter(e => e.errors.length);
79
+ return inputs.filter((e) => e.errors.length);
81
80
  });
82
81
  }
83
82
  updateValueAndValidityOnEvent(method) {
@@ -87,9 +86,7 @@ class FormGroup {
87
86
  self.setElementDirty(this);
88
87
  const selector = `input[name="${this.name}"]`;
89
88
  const hasMultipleBindings = [
90
- ...self
91
- .getFormElement()
92
- .querySelectorAll(selector).values()
89
+ ...self.getFormElement().querySelectorAll(selector).values(),
93
90
  ].length;
94
91
  let value = this.value;
95
92
  if (hasMultipleBindings === 1) {
@@ -104,14 +101,14 @@ class FormGroup {
104
101
  value = Number(value);
105
102
  }
106
103
  const inputsWithBindings = [
107
- ...(self.getFormElement().querySelectorAll(`input[name="${this.name}"]:checked`)).values()
104
+ ...(self.getFormElement().querySelectorAll(`input[name="${this.name}"]:checked`)).values(),
108
105
  ];
109
106
  if (hasMultipleBindings > 1) {
110
107
  if (!self.options.multi && this.type === 'checkbox') {
111
- value = inputsWithBindings.map(e => e.value);
108
+ value = inputsWithBindings.map((e) => e.value);
112
109
  }
113
110
  if (self.options.multi) {
114
- inputsWithBindings.forEach(el => (el.checked = false));
111
+ inputsWithBindings.forEach((el) => (el.checked = false));
115
112
  this.checked = true;
116
113
  }
117
114
  }
@@ -158,16 +155,17 @@ class FormGroup {
158
155
  return form;
159
156
  }
160
157
  querySelectAll(name) {
161
- return [...this.form.querySelectorAll(name).values()];
158
+ return [
159
+ ...this.form.querySelectorAll(name).values(),
160
+ ];
162
161
  }
163
162
  querySelectorAllInputs() {
164
- return [
165
- ...this.querySelectAll('input'),
166
- ...this.querySelectAll('select'),
167
- ...this.querySelectAll('textarea'),
168
- ]
169
- .filter(el => this.isInputPresentOnStage(el))
170
- .filter(el => !!el.name);
163
+ var _a;
164
+ return [...((_a = this.options.customElements) !== null && _a !== void 0 ? _a : []), 'input', 'select', 'textarea']
165
+ .map((item) => this.querySelectAll(item))
166
+ .flat()
167
+ .filter((el) => this.isInputPresentOnStage(el))
168
+ .filter((el) => !!el.name);
171
169
  }
172
170
  mapEventToInputs(inputs = []) {
173
171
  return inputs.map((el) => {
@@ -176,10 +174,10 @@ class FormGroup {
176
174
  el[strategy] = function () { };
177
175
  }
178
176
  const customAttributes = Object.keys(el.attributes)
179
- .map(k => el.attributes[k].name.startsWith('#') ? el.attributes[k] : null)
180
- .filter(i => !!i);
177
+ .map((k) => (el.attributes[k].name.startsWith('#') ? el.attributes[k] : null))
178
+ .filter((i) => !!i);
181
179
  if (customAttributes.length) {
182
- const attr = customAttributes.find(a => a.name.startsWith('#'));
180
+ const attr = customAttributes.find((a) => a.name.startsWith('#'));
183
181
  this.parentElement[attr.name.replace('#', '')] = el;
184
182
  }
185
183
  el.addEventListener('blur', () => __awaiter(this, void 0, void 0, function* () {
@@ -206,7 +204,7 @@ class FormGroup {
206
204
  if (input.outerHTML === '<input type="submit" style="display: none;">') {
207
205
  return;
208
206
  }
209
- const isInputPresent = Object.keys(this.value).filter(v => v === input.name);
207
+ const isInputPresent = Object.keys(this.value).filter((v) => v === input.name);
210
208
  return isInputPresent.length;
211
209
  }
212
210
  validate(element) {
@@ -217,11 +215,9 @@ class FormGroup {
217
215
  if (!element.checkValidity()) {
218
216
  return {
219
217
  errors: errors.concat(Object.keys(form_tokens_1.InputValidityState)
220
- .map(key => element.validity[key]
221
- ? { key, message: element.validationMessage }
222
- : null)
223
- .filter(i => !!i)),
224
- element
218
+ .map((key) => element.validity[key] ? { key, message: element.validationMessage } : null)
219
+ .filter((i) => !!i)),
220
+ element,
225
221
  };
226
222
  }
227
223
  errors = yield this.mapInputErrors(element);
@@ -250,7 +246,7 @@ class FormGroup {
250
246
  delete this.errors[element.name][this.errorMap.get(v)];
251
247
  }
252
248
  })));
253
- return res.filter(i => !!i);
249
+ return res.filter((i) => !!i);
254
250
  });
255
251
  }
256
252
  get(name) {
@@ -311,7 +307,7 @@ class FormGroup {
311
307
  return this;
312
308
  }
313
309
  setInputs(inputs) {
314
- this.inputs = new Map(inputs.map(e => {
310
+ this.inputs = new Map(inputs.map((e) => {
315
311
  e.value = this.getValue(e.name);
316
312
  return [e.name, e];
317
313
  }));
@@ -9,6 +9,11 @@ export interface FormOptions {
9
9
  /** When set to true `.valueChanges` will emit values only
10
10
  * if current input validation passes, default behavior is to emit every change fro */
11
11
  strict?: boolean;
12
+ /**
13
+ * When set form will expand capabilities by selecting another custom element made as a form element
14
+ * Example can be found here https://gist.github.com/Stradivario/57acf0fa19900867a7f55b0f01251d6e
15
+ * */
16
+ customElements?: string[];
12
17
  }
13
18
  export interface FormInputOptions {
14
19
  [key: string]: [string, Function[]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/forms",
3
- "version": "0.7.210",
3
+ "version": "0.7.211",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Kristiyan Tachev",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  "build": "tsc"
13
13
  },
14
14
  "devDependencies": {
15
- "@rxdi/lit-html": "^0.7.209",
15
+ "@rxdi/lit-html": "^0.7.210",
16
16
  "@types/node": "^25.0.3",
17
17
  "rxjs": "^7.8.2",
18
18
  "typescript": "^5.9.3"