@maif/react-forms 1.0.55 → 1.0.56
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 +37 -8
- package/lib/esm/index.js +40 -30
- package/lib/index.js +40 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,12 +18,12 @@ yarn add @maif/react-forms
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
# Usage
|
|
21
|
-
You must define a form flow (this is just a javascript array which
|
|
21
|
+
You must define a form flow (this is just a javascript array which represents the rendering order of the form fields) and a schema (that defines all fields of your form with types or constraints for example)
|
|
22
22
|
|
|
23
23
|
## example
|
|
24
24
|
|
|
25
25
|
```javascript
|
|
26
|
-
import { Form, type, format, constraints } from 'react-forms'
|
|
26
|
+
import { Form, type, format, constraints } from '@maif/react-forms'
|
|
27
27
|
|
|
28
28
|
export const Example = () => {
|
|
29
29
|
const schema = {
|
|
@@ -64,7 +64,7 @@ export const Example = () => {
|
|
|
64
64
|
## schema properties
|
|
65
65
|
|
|
66
66
|
- **type** (required): the type of value. It provided by the imported object `type`. It could be just string like `string`, `number`, `bool`, `object`, `date` or `file`
|
|
67
|
-
- **format**: Over the type you can display a special format for the field. It provided by the imported object `format` or just a string
|
|
67
|
+
- **format**: Over the type you can display a special format for the field. It is provided by the imported object `format` or just a string
|
|
68
68
|
- `select`: display a [react-select](https://react-select.com/home) field with provided options
|
|
69
69
|
- `buttonsSelect`: display a buttons group, drawn with the same options than the format `select`
|
|
70
70
|
- `code`: if the type is `string`, display a code input (draw with [react-ace](https://github.com/securingsincity/react-ace)) (add a props.setRef to get ace editor ref)
|
|
@@ -226,6 +226,7 @@ By default all fields of the form are nullable (they can accept `null` or `undef
|
|
|
226
226
|
- [`constraints.test(name: string, message?:string, test: (val: any) => boolean | Promise<boolean>)`](#constraintstestname-string-messagestring-test-val-any--boolean--promiseboolean)
|
|
227
227
|
- [`constraints.when(ref: string, test: (val: any) => boolean, then: any = [], otherwise: any = [])`](#constraintswhenref-string-test-val-any--boolean-then-any---otherwise-any--)
|
|
228
228
|
- [`constraints.oneOf(arrayOfValues: any[], message?:string)`](#constraintsoneofarrayofvalues-any-messagestring)
|
|
229
|
+
- [`constraints.ref(ref: any)`](#constraintsrefrefany)
|
|
229
230
|
- [string](#string)
|
|
230
231
|
- [string or number](#string-or-number)
|
|
231
232
|
- [number](#number)
|
|
@@ -279,6 +280,7 @@ the following methods works for all type types of value.
|
|
|
279
280
|
|
|
280
281
|
#### `constraints.oneOf(arrayOfValues: any[], message?:string)`
|
|
281
282
|
Whitelist a set of values and display an error under field if the provided value is not contains in this set.
|
|
283
|
+
Values can also be a [`reference`](#constraintsrefrefany) of value
|
|
282
284
|
|
|
283
285
|
```javascript
|
|
284
286
|
constraints.oneOf(['foo', 'bar'], 'not foo or bar :(')
|
|
@@ -287,6 +289,33 @@ the following methods works for all type types of value.
|
|
|
287
289
|
{type: 'oneOf', arrayOfValues: ['foo', 'bar'], message: 'not foo or bar :('}
|
|
288
290
|
```
|
|
289
291
|
|
|
292
|
+
#### `constraints.ref(ref:any)`
|
|
293
|
+
Some constraints accepts reference as property. This methods create a reference to another field.
|
|
294
|
+
Refs are evaluated in the proper order so that the ref value is resolved before the field using the ref (be careful of circular dependencies!).
|
|
295
|
+
|
|
296
|
+
```javascript
|
|
297
|
+
const schema = {
|
|
298
|
+
dad_age: { type: type.number},
|
|
299
|
+
son_age: {
|
|
300
|
+
type: type.number,
|
|
301
|
+
constraints: [
|
|
302
|
+
constraints.lessThan(constraints.ref('dad_age'), 'too old')
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
```javascript
|
|
308
|
+
const schema = {
|
|
309
|
+
dad_age: { type: 'number'},
|
|
310
|
+
son_age: {
|
|
311
|
+
type: 'number',
|
|
312
|
+
constraints: [
|
|
313
|
+
{type: 'lessThan', ref: { ref: 'dad_age' }, message: 'too old !'}
|
|
314
|
+
]
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
290
319
|
### string
|
|
291
320
|
the following methods works for string values. All methods for [mixed](#mixed) are available.
|
|
292
321
|
|
|
@@ -324,13 +353,13 @@ the following methods works for string or number values. All methods for [mixed]
|
|
|
324
353
|
|
|
325
354
|
|
|
326
355
|
#### `constraints.min(ref: number | Reference<number>, message: string)`
|
|
327
|
-
Set the minimum value allowed and display an error if the provided value (for a number) or the length of the string is bigger.
|
|
356
|
+
Set the minimum value allowed and display an error if the provided value (for a number) or the length of the string is bigger. Provided value can be a number or a [`reference`](#constraintsrefrefany) to a number
|
|
328
357
|
```javascript
|
|
329
358
|
{type: 'min', ref: 1, message: 'too small'}
|
|
330
359
|
```
|
|
331
360
|
|
|
332
361
|
#### `constraints.max(ref: number | Reference<number>, message: string)`
|
|
333
|
-
Set the maximun value allowed and display an error if provided value (for a number) or the length of the string is smaller.
|
|
362
|
+
Set the maximun value allowed and display an error if provided value (for a number) or the length of the string is smaller. value can be a number or a [`reference`](#constraintsrefrefany) to a number
|
|
334
363
|
```javascript
|
|
335
364
|
{type: 'max', ref: 5, message: 'too high'}
|
|
336
365
|
```
|
|
@@ -356,13 +385,13 @@ The value must be aa integer number and display an error if it's not.
|
|
|
356
385
|
```
|
|
357
386
|
|
|
358
387
|
#### `constraints.lessThan(ref: number | Reference<number>, message: string)`
|
|
359
|
-
Set the maximun value allowed and display an error if provided value (for a number) or the length of the string is smaller.
|
|
388
|
+
Set the maximun value allowed and display an error if provided value (for a number) or the length of the string is smaller. value can be a number or a [`reference`](#constraintsrefrefany) to a number
|
|
360
389
|
```javascript
|
|
361
390
|
{type: 'lessThan', ref: 5, message: 'less please'}
|
|
362
391
|
```
|
|
363
392
|
|
|
364
393
|
#### `constraints.moreThan(ref: number | Reference<number>, message: string)`
|
|
365
|
-
Set the minimum value allowed and display an error if provided value (for a number) or the length of the string is bigger.
|
|
394
|
+
Set the minimum value allowed and display an error if provided value (for a number) or the length of the string is bigger. value can be a number or a [`reference`](#constraintsrefrefany) to a number
|
|
366
395
|
```javascript
|
|
367
396
|
{type: 'moreThan', ref: 5, message: 'more please'}
|
|
368
397
|
```
|
|
@@ -371,7 +400,7 @@ Set the minimum value allowed and display an error if provided value (for a numb
|
|
|
371
400
|
the following methods works for basic types if the format is define to `array`. All methods for [mixed](#mixed) are available.
|
|
372
401
|
|
|
373
402
|
#### `constraints.length(value: number | Reference<number>, message?:string)`
|
|
374
|
-
Set the length of the array and display an error if it's different.
|
|
403
|
+
Set the length of the array and display an error if it's different. value can be a number or a [`reference`](#constraintsrefrefany) to a number
|
|
375
404
|
```javascript
|
|
376
405
|
{type: 'length', ref: 5, message: 'this array must have 5 elements'}
|
|
377
406
|
```
|
package/lib/esm/index.js
CHANGED
|
@@ -74,7 +74,8 @@ var _matches = function matches() {
|
|
|
74
74
|
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This field does not match the pattern";
|
|
75
75
|
return function (r) {
|
|
76
76
|
return r.matches(regexp, {
|
|
77
|
-
message: message
|
|
77
|
+
message: message,
|
|
78
|
+
excludeEmptyString: false
|
|
78
79
|
});
|
|
79
80
|
};
|
|
80
81
|
}; //string & number
|
|
@@ -215,7 +216,7 @@ var _oneOf = function oneOf(arrayOfValues) {
|
|
|
215
216
|
return function (r) {
|
|
216
217
|
return r.oneOf(arrayOfValues.map(maybeRef), message);
|
|
217
218
|
};
|
|
218
|
-
};
|
|
219
|
+
}; //todo: rename by notOneOf
|
|
219
220
|
|
|
220
221
|
var _blacklist = function blacklist(arrayOfValues) {
|
|
221
222
|
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This value can't include the following values ".concat(arrayOfValues.join(', '));
|
|
@@ -936,6 +937,9 @@ var arrayFlatten = function arrayFlatten(array) {
|
|
|
936
937
|
|
|
937
938
|
return array;
|
|
938
939
|
};
|
|
940
|
+
var isDefined = function isDefined(value) {
|
|
941
|
+
return value !== null && value !== undefined;
|
|
942
|
+
};
|
|
939
943
|
|
|
940
944
|
var valueToSelectOption = function valueToSelectOption(value) {
|
|
941
945
|
var possibleValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -1116,7 +1120,6 @@ var SelectInput = /*#__PURE__*/React.forwardRef(function (props, _) {
|
|
|
1116
1120
|
value: value,
|
|
1117
1121
|
isDisabled: props.disabled,
|
|
1118
1122
|
placeholder: props.placeholder,
|
|
1119
|
-
isClearable: true,
|
|
1120
1123
|
onChange: onChange,
|
|
1121
1124
|
options: values,
|
|
1122
1125
|
onCreateOption: function onCreateOption(option) {
|
|
@@ -1131,7 +1134,6 @@ var SelectInput = /*#__PURE__*/React.forwardRef(function (props, _) {
|
|
|
1131
1134
|
name: "".concat(props.label, "-search"),
|
|
1132
1135
|
isLoading: loading,
|
|
1133
1136
|
value: value,
|
|
1134
|
-
isClearable: true,
|
|
1135
1137
|
defaultValue: value,
|
|
1136
1138
|
isDisabled: props.disabled,
|
|
1137
1139
|
placeholder: props.placeholder,
|
|
@@ -28963,15 +28965,14 @@ var CustomizableInput$1 = /*#__PURE__*/React.memo(function (props) {
|
|
|
28963
28965
|
return prev.field.value === next.field.value && next.errorDisplayed === prev.errorDisplayed;
|
|
28964
28966
|
});
|
|
28965
28967
|
var ControlledInput = function ControlledInput(_ref) {
|
|
28966
|
-
var
|
|
28967
|
-
step = _ref.step,
|
|
28968
|
+
var step = _ref.step,
|
|
28968
28969
|
entry = _ref.entry,
|
|
28969
28970
|
children = _ref.children,
|
|
28970
28971
|
component = _ref.component,
|
|
28971
28972
|
errorDisplayed = _ref.errorDisplayed;
|
|
28972
28973
|
|
|
28973
28974
|
var _useController = useController({
|
|
28974
|
-
defaultValue: defaultValue
|
|
28975
|
+
defaultValue: isDefined(step.defaultValue) ? step.defaultValue : null,
|
|
28975
28976
|
name: entry
|
|
28976
28977
|
}),
|
|
28977
28978
|
field = _useController.field;
|
|
@@ -29131,8 +29132,8 @@ var CustomizableInput = function CustomizableInput(props) {
|
|
|
29131
29132
|
return props.children;
|
|
29132
29133
|
};
|
|
29133
29134
|
|
|
29134
|
-
var defaultVal = function defaultVal(value, array, defaultValue) {
|
|
29135
|
-
if (
|
|
29135
|
+
var defaultVal = function defaultVal(value, array, defaultValue, type) {
|
|
29136
|
+
if (isDefined(defaultValue)) return defaultValue;
|
|
29136
29137
|
if (!!array) return [];
|
|
29137
29138
|
return value;
|
|
29138
29139
|
};
|
|
@@ -29169,9 +29170,17 @@ var cleanInputArray = function cleanInputArray(obj, defaultValues, flow, subSche
|
|
|
29169
29170
|
key = _ref5[0],
|
|
29170
29171
|
step = _ref5[1];
|
|
29171
29172
|
|
|
29172
|
-
var v;
|
|
29173
|
-
|
|
29174
|
-
if (
|
|
29173
|
+
var v = null;
|
|
29174
|
+
|
|
29175
|
+
if (obj) {
|
|
29176
|
+
v = obj[key];
|
|
29177
|
+
}
|
|
29178
|
+
|
|
29179
|
+
var maybeDefaultValue = defaultValues[key];
|
|
29180
|
+
|
|
29181
|
+
if (!v && isDefined(maybeDefaultValue)) {
|
|
29182
|
+
v = maybeDefaultValue;
|
|
29183
|
+
}
|
|
29175
29184
|
|
|
29176
29185
|
if (step.array && !step.render) {
|
|
29177
29186
|
return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, key, (v || []).map(function (value) {
|
|
@@ -29333,16 +29342,15 @@ var Form = /*#__PURE__*/React.forwardRef(function (_ref7, ref) {
|
|
|
29333
29342
|
|
|
29334
29343
|
var _useState = useState(false),
|
|
29335
29344
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29336
|
-
initialReseted = _useState2[0]
|
|
29337
|
-
|
|
29345
|
+
initialReseted = _useState2[0];
|
|
29346
|
+
_useState2[1]; // useEffect(() => {
|
|
29347
|
+
// reset(cleanInputArray(value, defaultValues, flow, schema))
|
|
29348
|
+
// setReset(true)
|
|
29349
|
+
// }, [reset])
|
|
29338
29350
|
|
|
29339
|
-
useEffect(function () {
|
|
29340
|
-
_reset(cleanInputArray(value, defaultValues, flow, schema));
|
|
29341
29351
|
|
|
29342
|
-
setReset(true);
|
|
29343
|
-
}, [_reset]);
|
|
29344
29352
|
useEffect(function () {
|
|
29345
|
-
|
|
29353
|
+
trigger();
|
|
29346
29354
|
}, [trigger, initialReseted]);
|
|
29347
29355
|
var _handleSubmit = methods.handleSubmit,
|
|
29348
29356
|
_methods$formState = methods.formState;
|
|
@@ -29355,7 +29363,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (_ref7, ref) {
|
|
|
29355
29363
|
var prev = usePrevious(value);
|
|
29356
29364
|
var prevSchema = usePrevious(schema);
|
|
29357
29365
|
useEffect(function () {
|
|
29358
|
-
if (!deepEqual(value, prev) || !deepEqual(schema, prevSchema)) {
|
|
29366
|
+
if (prev && prevSchema && !deepEqual(value, prev) || !deepEqual(schema, prevSchema)) {
|
|
29359
29367
|
_reset(_objectSpread2$1({}, cleanInputArray(value, defaultValues, flow, schema)));
|
|
29360
29368
|
}
|
|
29361
29369
|
}, [value, schema]);
|
|
@@ -29695,9 +29703,10 @@ var Step = function Step(_ref8) {
|
|
|
29695
29703
|
step: step,
|
|
29696
29704
|
entry: entry,
|
|
29697
29705
|
errorDisplayed: errorDisplayed
|
|
29698
|
-
}, /*#__PURE__*/React.createElement(SelectInput, {
|
|
29706
|
+
}, /*#__PURE__*/React.createElement(SelectInput, _extends({
|
|
29699
29707
|
className: classNames(classes.flex_grow_1, _defineProperty$1({}, classes.input__invalid, errorDisplayed)),
|
|
29700
|
-
disabled: functionalProperty(entry, step.disabled)
|
|
29708
|
+
disabled: functionalProperty(entry, step.disabled)
|
|
29709
|
+
}, step.props, {
|
|
29701
29710
|
possibleValues: step.options,
|
|
29702
29711
|
httpClient: httpClient,
|
|
29703
29712
|
isMulti: step.isMulti,
|
|
@@ -29705,7 +29714,7 @@ var Step = function Step(_ref8) {
|
|
|
29705
29714
|
transformer: step.transformer,
|
|
29706
29715
|
buttons: step.format === format.buttonsSelect,
|
|
29707
29716
|
optionsFrom: step.optionsFrom
|
|
29708
|
-
}));
|
|
29717
|
+
})));
|
|
29709
29718
|
}
|
|
29710
29719
|
|
|
29711
29720
|
default:
|
|
@@ -29729,8 +29738,9 @@ var Step = function Step(_ref8) {
|
|
|
29729
29738
|
step: step,
|
|
29730
29739
|
entry: entry,
|
|
29731
29740
|
errorDisplayed: errorDisplayed
|
|
29732
|
-
}, /*#__PURE__*/React.createElement(SelectInput, {
|
|
29733
|
-
className: classNames(classes.content, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29741
|
+
}, /*#__PURE__*/React.createElement(SelectInput, _extends({
|
|
29742
|
+
className: classNames(classes.content, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29743
|
+
}, step.props, {
|
|
29734
29744
|
possibleValues: step.options,
|
|
29735
29745
|
httpClient: httpClient,
|
|
29736
29746
|
isMulti: step.isMulti,
|
|
@@ -29739,7 +29749,7 @@ var Step = function Step(_ref8) {
|
|
|
29739
29749
|
transformer: step.transformer,
|
|
29740
29750
|
buttons: step.format === format.buttonsSelect,
|
|
29741
29751
|
optionsFrom: step.optionsFrom
|
|
29742
|
-
}));
|
|
29752
|
+
})));
|
|
29743
29753
|
|
|
29744
29754
|
default:
|
|
29745
29755
|
return /*#__PURE__*/React.createElement(ControlledInput, {
|
|
@@ -29755,7 +29765,6 @@ var Step = function Step(_ref8) {
|
|
|
29755
29765
|
|
|
29756
29766
|
case type.bool:
|
|
29757
29767
|
return /*#__PURE__*/React.createElement(ControlledInput, {
|
|
29758
|
-
defaultValue: defaultValue,
|
|
29759
29768
|
step: step,
|
|
29760
29769
|
entry: entry,
|
|
29761
29770
|
errorDisplayed: errorDisplayed
|
|
@@ -29772,8 +29781,9 @@ var Step = function Step(_ref8) {
|
|
|
29772
29781
|
step: step,
|
|
29773
29782
|
entry: entry,
|
|
29774
29783
|
errorDisplayed: errorDisplayed
|
|
29775
|
-
}, /*#__PURE__*/React.createElement(SelectInput, {
|
|
29776
|
-
className: classNames(classes.flex_grow_1, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29784
|
+
}, /*#__PURE__*/React.createElement(SelectInput, _extends({
|
|
29785
|
+
className: classNames(classes.flex_grow_1, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29786
|
+
}, step.props, {
|
|
29777
29787
|
possibleValues: step.options,
|
|
29778
29788
|
httpClient: httpClient,
|
|
29779
29789
|
isMulti: step.isMulti,
|
|
@@ -29782,7 +29792,7 @@ var Step = function Step(_ref8) {
|
|
|
29782
29792
|
transformer: step.transformer,
|
|
29783
29793
|
buttons: step.format === format.buttonsSelect,
|
|
29784
29794
|
optionsFrom: step.optionsFrom
|
|
29785
|
-
}));
|
|
29795
|
+
})));
|
|
29786
29796
|
|
|
29787
29797
|
case format.form:
|
|
29788
29798
|
//todo: disabled ?
|
package/lib/index.js
CHANGED
|
@@ -108,7 +108,8 @@ var _matches = function matches() {
|
|
|
108
108
|
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This field does not match the pattern";
|
|
109
109
|
return function (r) {
|
|
110
110
|
return r.matches(regexp, {
|
|
111
|
-
message: message
|
|
111
|
+
message: message,
|
|
112
|
+
excludeEmptyString: false
|
|
112
113
|
});
|
|
113
114
|
};
|
|
114
115
|
}; //string & number
|
|
@@ -249,7 +250,7 @@ var _oneOf = function oneOf(arrayOfValues) {
|
|
|
249
250
|
return function (r) {
|
|
250
251
|
return r.oneOf(arrayOfValues.map(maybeRef), message);
|
|
251
252
|
};
|
|
252
|
-
};
|
|
253
|
+
}; //todo: rename by notOneOf
|
|
253
254
|
|
|
254
255
|
var _blacklist = function blacklist(arrayOfValues) {
|
|
255
256
|
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This value can't include the following values ".concat(arrayOfValues.join(', '));
|
|
@@ -970,6 +971,9 @@ var arrayFlatten = function arrayFlatten(array) {
|
|
|
970
971
|
|
|
971
972
|
return array;
|
|
972
973
|
};
|
|
974
|
+
var isDefined = function isDefined(value) {
|
|
975
|
+
return value !== null && value !== undefined;
|
|
976
|
+
};
|
|
973
977
|
|
|
974
978
|
var valueToSelectOption = function valueToSelectOption(value) {
|
|
975
979
|
var possibleValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -1150,7 +1154,6 @@ var SelectInput = /*#__PURE__*/React__default["default"].forwardRef(function (pr
|
|
|
1150
1154
|
value: value,
|
|
1151
1155
|
isDisabled: props.disabled,
|
|
1152
1156
|
placeholder: props.placeholder,
|
|
1153
|
-
isClearable: true,
|
|
1154
1157
|
onChange: onChange,
|
|
1155
1158
|
options: values,
|
|
1156
1159
|
onCreateOption: function onCreateOption(option) {
|
|
@@ -1165,7 +1168,6 @@ var SelectInput = /*#__PURE__*/React__default["default"].forwardRef(function (pr
|
|
|
1165
1168
|
name: "".concat(props.label, "-search"),
|
|
1166
1169
|
isLoading: loading,
|
|
1167
1170
|
value: value,
|
|
1168
|
-
isClearable: true,
|
|
1169
1171
|
defaultValue: value,
|
|
1170
1172
|
isDisabled: props.disabled,
|
|
1171
1173
|
placeholder: props.placeholder,
|
|
@@ -28997,15 +28999,14 @@ var CustomizableInput$1 = /*#__PURE__*/React__default["default"].memo(function (
|
|
|
28997
28999
|
return prev.field.value === next.field.value && next.errorDisplayed === prev.errorDisplayed;
|
|
28998
29000
|
});
|
|
28999
29001
|
var ControlledInput = function ControlledInput(_ref) {
|
|
29000
|
-
var
|
|
29001
|
-
step = _ref.step,
|
|
29002
|
+
var step = _ref.step,
|
|
29002
29003
|
entry = _ref.entry,
|
|
29003
29004
|
children = _ref.children,
|
|
29004
29005
|
component = _ref.component,
|
|
29005
29006
|
errorDisplayed = _ref.errorDisplayed;
|
|
29006
29007
|
|
|
29007
29008
|
var _useController = reactHookForm.useController({
|
|
29008
|
-
defaultValue: defaultValue
|
|
29009
|
+
defaultValue: isDefined(step.defaultValue) ? step.defaultValue : null,
|
|
29009
29010
|
name: entry
|
|
29010
29011
|
}),
|
|
29011
29012
|
field = _useController.field;
|
|
@@ -29165,8 +29166,8 @@ var CustomizableInput = function CustomizableInput(props) {
|
|
|
29165
29166
|
return props.children;
|
|
29166
29167
|
};
|
|
29167
29168
|
|
|
29168
|
-
var defaultVal = function defaultVal(value, array, defaultValue) {
|
|
29169
|
-
if (
|
|
29169
|
+
var defaultVal = function defaultVal(value, array, defaultValue, type) {
|
|
29170
|
+
if (isDefined(defaultValue)) return defaultValue;
|
|
29170
29171
|
if (!!array) return [];
|
|
29171
29172
|
return value;
|
|
29172
29173
|
};
|
|
@@ -29203,9 +29204,17 @@ var cleanInputArray = function cleanInputArray(obj, defaultValues, flow, subSche
|
|
|
29203
29204
|
key = _ref5[0],
|
|
29204
29205
|
step = _ref5[1];
|
|
29205
29206
|
|
|
29206
|
-
var v;
|
|
29207
|
-
|
|
29208
|
-
if (
|
|
29207
|
+
var v = null;
|
|
29208
|
+
|
|
29209
|
+
if (obj) {
|
|
29210
|
+
v = obj[key];
|
|
29211
|
+
}
|
|
29212
|
+
|
|
29213
|
+
var maybeDefaultValue = defaultValues[key];
|
|
29214
|
+
|
|
29215
|
+
if (!v && isDefined(maybeDefaultValue)) {
|
|
29216
|
+
v = maybeDefaultValue;
|
|
29217
|
+
}
|
|
29209
29218
|
|
|
29210
29219
|
if (step.array && !step.render) {
|
|
29211
29220
|
return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, key, (v || []).map(function (value) {
|
|
@@ -29367,16 +29376,15 @@ var Form = /*#__PURE__*/React__default["default"].forwardRef(function (_ref7, re
|
|
|
29367
29376
|
|
|
29368
29377
|
var _useState = React.useState(false),
|
|
29369
29378
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29370
|
-
initialReseted = _useState2[0]
|
|
29371
|
-
|
|
29379
|
+
initialReseted = _useState2[0];
|
|
29380
|
+
_useState2[1]; // useEffect(() => {
|
|
29381
|
+
// reset(cleanInputArray(value, defaultValues, flow, schema))
|
|
29382
|
+
// setReset(true)
|
|
29383
|
+
// }, [reset])
|
|
29372
29384
|
|
|
29373
|
-
React.useEffect(function () {
|
|
29374
|
-
_reset(cleanInputArray(value, defaultValues, flow, schema));
|
|
29375
29385
|
|
|
29376
|
-
setReset(true);
|
|
29377
|
-
}, [_reset]);
|
|
29378
29386
|
React.useEffect(function () {
|
|
29379
|
-
|
|
29387
|
+
trigger();
|
|
29380
29388
|
}, [trigger, initialReseted]);
|
|
29381
29389
|
var _handleSubmit = methods.handleSubmit,
|
|
29382
29390
|
_methods$formState = methods.formState;
|
|
@@ -29389,7 +29397,7 @@ var Form = /*#__PURE__*/React__default["default"].forwardRef(function (_ref7, re
|
|
|
29389
29397
|
var prev = usePrevious(value);
|
|
29390
29398
|
var prevSchema = usePrevious(schema);
|
|
29391
29399
|
React.useEffect(function () {
|
|
29392
|
-
if (!deepEqual__default["default"](value, prev) || !deepEqual__default["default"](schema, prevSchema)) {
|
|
29400
|
+
if (prev && prevSchema && !deepEqual__default["default"](value, prev) || !deepEqual__default["default"](schema, prevSchema)) {
|
|
29393
29401
|
_reset(_objectSpread2$1({}, cleanInputArray(value, defaultValues, flow, schema)));
|
|
29394
29402
|
}
|
|
29395
29403
|
}, [value, schema]);
|
|
@@ -29729,9 +29737,10 @@ var Step = function Step(_ref8) {
|
|
|
29729
29737
|
step: step,
|
|
29730
29738
|
entry: entry,
|
|
29731
29739
|
errorDisplayed: errorDisplayed
|
|
29732
|
-
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, {
|
|
29740
|
+
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({
|
|
29733
29741
|
className: classNames__default["default"](classes.flex_grow_1, _defineProperty$1({}, classes.input__invalid, errorDisplayed)),
|
|
29734
|
-
disabled: functionalProperty(entry, step.disabled)
|
|
29742
|
+
disabled: functionalProperty(entry, step.disabled)
|
|
29743
|
+
}, step.props, {
|
|
29735
29744
|
possibleValues: step.options,
|
|
29736
29745
|
httpClient: httpClient,
|
|
29737
29746
|
isMulti: step.isMulti,
|
|
@@ -29739,7 +29748,7 @@ var Step = function Step(_ref8) {
|
|
|
29739
29748
|
transformer: step.transformer,
|
|
29740
29749
|
buttons: step.format === format.buttonsSelect,
|
|
29741
29750
|
optionsFrom: step.optionsFrom
|
|
29742
|
-
}));
|
|
29751
|
+
})));
|
|
29743
29752
|
}
|
|
29744
29753
|
|
|
29745
29754
|
default:
|
|
@@ -29763,8 +29772,9 @@ var Step = function Step(_ref8) {
|
|
|
29763
29772
|
step: step,
|
|
29764
29773
|
entry: entry,
|
|
29765
29774
|
errorDisplayed: errorDisplayed
|
|
29766
|
-
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, {
|
|
29767
|
-
className: classNames__default["default"](classes.content, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29775
|
+
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({
|
|
29776
|
+
className: classNames__default["default"](classes.content, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29777
|
+
}, step.props, {
|
|
29768
29778
|
possibleValues: step.options,
|
|
29769
29779
|
httpClient: httpClient,
|
|
29770
29780
|
isMulti: step.isMulti,
|
|
@@ -29773,7 +29783,7 @@ var Step = function Step(_ref8) {
|
|
|
29773
29783
|
transformer: step.transformer,
|
|
29774
29784
|
buttons: step.format === format.buttonsSelect,
|
|
29775
29785
|
optionsFrom: step.optionsFrom
|
|
29776
|
-
}));
|
|
29786
|
+
})));
|
|
29777
29787
|
|
|
29778
29788
|
default:
|
|
29779
29789
|
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
@@ -29789,7 +29799,6 @@ var Step = function Step(_ref8) {
|
|
|
29789
29799
|
|
|
29790
29800
|
case type.bool:
|
|
29791
29801
|
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29792
|
-
defaultValue: defaultValue,
|
|
29793
29802
|
step: step,
|
|
29794
29803
|
entry: entry,
|
|
29795
29804
|
errorDisplayed: errorDisplayed
|
|
@@ -29806,8 +29815,9 @@ var Step = function Step(_ref8) {
|
|
|
29806
29815
|
step: step,
|
|
29807
29816
|
entry: entry,
|
|
29808
29817
|
errorDisplayed: errorDisplayed
|
|
29809
|
-
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, {
|
|
29810
|
-
className: classNames__default["default"](classes.flex_grow_1, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29818
|
+
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({
|
|
29819
|
+
className: classNames__default["default"](classes.flex_grow_1, _defineProperty$1({}, classes.input__invalid, errorDisplayed))
|
|
29820
|
+
}, step.props, {
|
|
29811
29821
|
possibleValues: step.options,
|
|
29812
29822
|
httpClient: httpClient,
|
|
29813
29823
|
isMulti: step.isMulti,
|
|
@@ -29816,7 +29826,7 @@ var Step = function Step(_ref8) {
|
|
|
29816
29826
|
transformer: step.transformer,
|
|
29817
29827
|
buttons: step.format === format.buttonsSelect,
|
|
29818
29828
|
optionsFrom: step.optionsFrom
|
|
29819
|
-
}));
|
|
29829
|
+
})));
|
|
29820
29830
|
|
|
29821
29831
|
case format.form:
|
|
29822
29832
|
//todo: disabled ?
|