@rxdi/forms 0.7.215 → 0.7.216

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/README.md CHANGED
@@ -154,6 +154,8 @@ this.form.patchValue({
154
154
  }
155
155
  });
156
156
  // Only updates 'isActive', leaves other fields untouched.
157
+ ````
158
+
157
159
  ### Dynamic Array Inputs (FormArray)
158
160
 
159
161
  For lists of primitive values, use `FormArray` with an `itemFactory` and automatic model binding. This removes the need for manual population.
@@ -88,15 +88,14 @@ class FormArray {
88
88
  unsubscribe() {
89
89
  this.subscriptions.forEach((sub) => sub.unsubscribe());
90
90
  this.subscriptions.clear();
91
- this.controls.forEach((c) => c.unsubscribe && c.unsubscribe());
91
+ this.controls.forEach((c) => { var _a; return (_a = c.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(c); });
92
92
  }
93
93
  updateValue() {
94
94
  this._valueChanges.next(this.value);
95
95
  }
96
96
  requestUpdate() {
97
- if (this.parentElement) {
98
- this.parentElement.requestUpdate();
99
- }
97
+ var _a;
98
+ (_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.requestUpdate();
100
99
  }
101
100
  setParentElement(parent) {
102
101
  this.parentElement = parent;
@@ -118,9 +117,7 @@ class FormArray {
118
117
  return;
119
118
  }
120
119
  values.forEach((v, i) => {
121
- if (this.controls[i]) {
122
- this.controls[i].value = v;
123
- }
120
+ this.controls[i] && (this.controls[i].value = v);
124
121
  });
125
122
  this.updateValue();
126
123
  }
@@ -129,13 +126,9 @@ class FormArray {
129
126
  return;
130
127
  }
131
128
  values.forEach((v, i) => {
132
- if (this.controls[i]) {
133
- if (this.controls[i]['patchValue']) {
134
- this.controls[i]['patchValue'](v);
135
- }
136
- else {
137
- this.controls[i].value = v;
138
- }
129
+ const control = this.controls[i];
130
+ if (control) {
131
+ control.patchValue ? control.patchValue(v) : (control.value = v);
139
132
  }
140
133
  else if (this.options.itemFactory) {
141
134
  this.push(this.options.itemFactory(v));
@@ -1,5 +1,5 @@
1
1
  import { LitElement } from '@rxdi/lit-html';
2
- import { AbstractControl, AbstractInput, ErrorObject, FormInputOptions, FormOptions, NestedKeyOf, UnwrapValue, ValidatorFn, DeepPropType } from './form.tokens';
2
+ import { AbstractControl, AbstractInput, DeepPropType, ErrorObject, FormInputOptions, FormOptions, NestedKeyOf, UnwrapValue, ValidatorFn } from './form.tokens';
3
3
  export declare class FormGroup<T = FormInputOptions, E = {
4
4
  [key: string]: never;
5
5
  }> implements AbstractControl<UnwrapValue<T>> {
@@ -46,10 +46,13 @@ class FormGroup {
46
46
  }
47
47
  }
48
48
  init() {
49
+ if (!this.parentElement) {
50
+ return;
51
+ }
49
52
  this.setFormElement(this.querySelectForm(this.parentElement.shadowRoot || this.parentElement)).setInputs(this.mapEventToInputs(this.querySelectorAllInputs()));
50
53
  this.controls.forEach((c) => {
51
- if (c.init)
52
- c.init();
54
+ var _a;
55
+ (_a = c.init) === null || _a === void 0 ? void 0 : _a.call(c);
53
56
  });
54
57
  }
55
58
  prepareValues() {
@@ -84,9 +87,8 @@ class FormGroup {
84
87
  setParentElement(parent) {
85
88
  this.parentElement = parent;
86
89
  this.controls.forEach((c) => {
87
- if (c.setParentElement) {
88
- c.setParentElement(parent);
89
- }
90
+ var _a;
91
+ (_a = c.setParentElement) === null || _a === void 0 ? void 0 : _a.call(c, parent);
90
92
  });
91
93
  return this;
92
94
  }
@@ -96,9 +98,8 @@ class FormGroup {
96
98
  setOptions(options) {
97
99
  this.options = options;
98
100
  this.controls.forEach((c) => {
99
- if (c.setOptions) {
100
- c.setOptions(Object.assign(Object.assign({}, options), { namespace: this.options.namespace ? `${this.options.namespace}.${c.name}` : c.name }));
101
- }
101
+ var _a;
102
+ (_a = c.setOptions) === null || _a === void 0 ? void 0 : _a.call(c, Object.assign(Object.assign({}, options), { namespace: this.options.namespace ? `${this.options.namespace}.${c.name}` : c.name }));
102
103
  });
103
104
  return this;
104
105
  }
@@ -200,6 +201,9 @@ class FormGroup {
200
201
  if (this.options['form']) {
201
202
  return this.options['form'];
202
203
  }
204
+ if (!(shadowRoot === null || shadowRoot === void 0 ? void 0 : shadowRoot.querySelector)) {
205
+ return null;
206
+ }
203
207
  const form = shadowRoot.querySelector(`form[name="${this.options.name}"]`);
204
208
  if (!form) {
205
209
  throw new Error(`Form element with name "${this.options.name}" not present inside ${this.getParentElement().outerHTML} component`);
@@ -335,7 +339,7 @@ class FormGroup {
335
339
  const names = String(name).split('.');
336
340
  const key = names.shift();
337
341
  const control = this.controls.get(key);
338
- if (control && control.get) {
342
+ if (control === null || control === void 0 ? void 0 : control.get) {
339
343
  return control.get(names.join('.'));
340
344
  }
341
345
  }
@@ -390,8 +394,9 @@ class FormGroup {
390
394
  return;
391
395
  }
392
396
  Object.keys(value).forEach((key) => {
393
- if (this.controls.has(key) && this.controls.get(key)['patchValue']) {
394
- this.controls.get(key)['patchValue'](value[key]);
397
+ const control = this.controls.get(key);
398
+ if (control === null || control === void 0 ? void 0 : control['patchValue']) {
399
+ control['patchValue'](value[key]);
395
400
  }
396
401
  else {
397
402
  this.setValue(key, value[key]);
@@ -417,8 +422,8 @@ class FormGroup {
417
422
  setFormElement(form) {
418
423
  this.form = form;
419
424
  this.controls.forEach((c) => {
420
- if (c.setFormElement)
421
- c.setFormElement(form);
425
+ var _a;
426
+ (_a = c.setFormElement) === null || _a === void 0 ? void 0 : _a.call(c, form);
422
427
  });
423
428
  return this;
424
429
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/forms",
3
- "version": "0.7.215",
3
+ "version": "0.7.216",
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.214",
15
+ "@rxdi/lit-html": "^0.7.215",
16
16
  "@types/node": "^25.0.3",
17
17
  "rxjs": "^7.8.2",
18
18
  "typescript": "^5.9.3"