@rxap/forms 13.0.0 → 13.0.1

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.
@@ -170,8 +170,9 @@ class RxapFormArray extends FormArray {
170
170
  *
171
171
  * @param index (optional) the index where the control should be created
172
172
  * @param state (optional) the initial state of the new control
173
+ * @param options (optional) ControlEventOptions
173
174
  */
174
- insertAt(index, state) {
175
+ insertAt(index, state, options) {
175
176
  const insertIndex = index ?? this.controls.length;
176
177
  const controlOrDefinition = this._builder(state, {
177
178
  controlId: insertIndex.toFixed(0),
@@ -186,10 +187,10 @@ class RxapFormArray extends FormArray {
186
187
  // call the super insert after the update, bc the insert method will
187
188
  // trigger a change detection
188
189
  if (controlOrDefinition instanceof AbstractControl) {
189
- super.insert(insertIndex, controlOrDefinition);
190
+ super.insert(insertIndex, controlOrDefinition, options);
190
191
  }
191
192
  else {
192
- super.insert(insertIndex, controlOrDefinition.rxapFormGroup);
193
+ super.insert(insertIndex, controlOrDefinition.rxapFormGroup, options);
193
194
  }
194
195
  }
195
196
  disabledWhile(observable, options) {
@@ -214,9 +215,24 @@ class RxapFormArray extends FormArray {
214
215
  markAllAsPristine() {
215
216
  markAllPristine(this);
216
217
  }
218
+ coerceValue(value) {
219
+ for (let index = 0; index < value.length; index++) {
220
+ if (!this.at(index)) {
221
+ this.insertAt(index, value[index]);
222
+ }
223
+ }
224
+ }
217
225
  setValue(valueOrObservable, options) {
218
226
  if (isObservable(valueOrObservable)) {
219
- return valueOrObservable.subscribe((value) => super.setValue(value, options));
227
+ return valueOrObservable.subscribe((value) => {
228
+ if (options?.coerce) {
229
+ this.coerceValue(value);
230
+ }
231
+ super.setValue(value, options);
232
+ });
233
+ }
234
+ if (options?.coerce) {
235
+ this.coerceValue(valueOrObservable);
220
236
  }
221
237
  super.setValue(valueOrObservable, options);
222
238
  }
@@ -234,9 +250,15 @@ class RxapFormArray extends FormArray {
234
250
  patchValue(valueOrObservable, options) {
235
251
  if (isObservable(valueOrObservable)) {
236
252
  return valueOrObservable.subscribe((value) => {
253
+ if (options?.coerce) {
254
+ this.coerceValue(value);
255
+ }
237
256
  super.patchValue(value, options);
238
257
  });
239
258
  }
259
+ if (options?.coerce) {
260
+ this.coerceValue(valueOrObservable);
261
+ }
240
262
  super.patchValue(valueOrObservable, options);
241
263
  }
242
264
  hasErrorAndDirty(errorCode, path) {
@@ -252,20 +274,20 @@ class RxapFormArray extends FormArray {
252
274
  setEnable(enable = true, opts) {
253
275
  enableControl(this, enable, opts);
254
276
  }
255
- push(control) {
277
+ push(control, options) {
256
278
  if (isDevMode()) {
257
279
  console.warn('It is not recommend to use the FormArray.push method');
258
280
  }
259
- return super.push(control);
281
+ return super.push(control, options);
260
282
  }
261
283
  setDisable(disable = true, opts) {
262
284
  disableControl(this, disable, opts);
263
285
  }
264
- setControl(index, control) {
286
+ setControl(index, control, options) {
265
287
  if (isDevMode()) {
266
288
  console.warn('It is not recommend to use the FormArray.setControl method');
267
289
  }
268
- return super.setControl(index, control);
290
+ return super.setControl(index, control, options);
269
291
  }
270
292
  markAsTouched(opts) {
271
293
  super.markAsTouched(opts);