@try-at-software/input-elements 1.2.4 → 1.2.6

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.
@@ -1,4 +1,4 @@
1
- import { IChangingInputElement } from './IChangingInputElement';
1
+ import { IChangingInputElement, ResetValueOptions } from './IChangingInputElement';
2
2
  import { UpdateCallback } from './IInputElement';
3
3
  import { InputElement } from './InputElement';
4
4
  export declare abstract class ChangingInputElement<TValue> extends InputElement implements IChangingInputElement<TValue> {
@@ -11,6 +11,7 @@ export declare abstract class ChangingInputElement<TValue> extends InputElement
11
11
  /** @inheritdoc */
12
12
  setValue(value: TValue): void;
13
13
  /** @inheritdoc */
14
- resetValue(): void;
14
+ resetValue(options?: ResetValueOptions): void;
15
15
  protected abstract setInternalValue(value: TValue, isInitial: boolean): void;
16
+ protected abstract resetInternalValue(): void;
16
17
  }
@@ -24,11 +24,16 @@ class ChangingInputElement extends InputElement_1.InputElement {
24
24
  this.updateInternally();
25
25
  }
26
26
  /** @inheritdoc */
27
- resetValue() {
27
+ resetValue(options) {
28
28
  if (!this._valueIsSet && !this._initialValueIsSet)
29
29
  return;
30
- this.setInternalValue(undefined, false);
31
- this.updateInternally();
30
+ this._valueIsSet = false;
31
+ if (!(options === null || options === void 0 ? void 0 : options.avoidFallbackToInitialValue) && this._initialValueIsSet) {
32
+ this._initialValueIsSet = false;
33
+ this.setInitialValue(this.initialValue);
34
+ }
35
+ else
36
+ this.resetInternalValue();
32
37
  }
33
38
  }
34
39
  exports.ChangingInputElement = ChangingInputElement;
@@ -41,5 +41,7 @@ export declare class DynamicListInputElement<TValue> extends ExtendedInputElemen
41
41
  private reorder;
42
42
  private convert;
43
43
  protected setInternalValue(valueChange: IDynamicValueChange<TValue>[], isInitial: boolean): void;
44
+ /** @inheritdoc */
45
+ protected resetInternalValue(): void;
44
46
  private filterInputs;
45
47
  }
@@ -110,6 +110,10 @@ class DynamicListInputElement extends ExtendedInputElement_1.ExtendedInputElemen
110
110
  this._inputs = newInputs;
111
111
  (_a = this._componentRef.current) === null || _a === void 0 ? void 0 : _a.update(this._inputs);
112
112
  }
113
+ /** @inheritdoc */
114
+ resetInternalValue() {
115
+ this._inputs = [];
116
+ }
113
117
  filterInputs() {
114
118
  var _a;
115
119
  return (_a = this._inputs) === null || _a === void 0 ? void 0 : _a.filter((i) => !!(i === null || i === void 0 ? void 0 : i.input));
@@ -1,4 +1,7 @@
1
1
  import { IInputElement } from './IInputElement';
2
+ export declare type ResetValueOptions = {
3
+ avoidFallbackToInitialValue?: boolean;
4
+ };
2
5
  export interface IChangingInputElement<TValue> extends IInputElement {
3
6
  /**
4
7
  * A method used to set new value, validate it and update the form.
@@ -13,6 +16,8 @@ export interface IChangingInputElement<TValue> extends IInputElement {
13
16
  setInitialValue(value: TValue): void;
14
17
  /**
15
18
  * This method will reset the current value of the input element.
19
+ *
20
+ * @param options Additional options that can be used to refine the reset process.
16
21
  */
17
- resetValue(): void;
22
+ resetValue(options?: ResetValueOptions): void;
18
23
  }
@@ -26,6 +26,8 @@ export declare class SingleValueInputElement<TValue, TOperativeProps, TDynamicPr
26
26
  /** @inheritdoc */
27
27
  protected setInternalValue(value: TValue, isInitial: boolean): void;
28
28
  /** @inheritdoc */
29
+ protected resetInternalValue(): void;
30
+ /** @inheritdoc */
29
31
  get hasChanges(): boolean;
30
32
  /** @inheritdoc */
31
33
  value: TValue;
@@ -78,6 +78,17 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
78
78
  this.invalidValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x());
79
79
  }
80
80
  /** @inheritdoc */
81
+ resetInternalValue() {
82
+ var _a;
83
+ this.setError(undefined);
84
+ this.value = undefined;
85
+ if (this._isInvalidated)
86
+ this._isInvalidated = false;
87
+ if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current)
88
+ this._componentRef.current.update(undefined);
89
+ this.updateInternally();
90
+ }
91
+ /** @inheritdoc */
81
92
  get hasChanges() {
82
93
  var _a;
83
94
  return !!((_a = this._configuration) === null || _a === void 0 ? void 0 : _a.comparator)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@try-at-software/input-elements",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "A package providing different input elements that are extensible and easily configurable for your custom needs.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",