@rjsf/core 5.0.0-beta.15 → 5.0.0-beta.16
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/dist/core.cjs.development.js +75 -50
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +75 -50
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +76 -51
- package/dist/core.umd.development.js.map +1 -1
- package/dist/core.umd.production.min.js +1 -1
- package/dist/core.umd.production.min.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/package.json +5 -5
|
@@ -171,42 +171,11 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
171
171
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
172
172
|
};
|
|
173
173
|
_this.onAddClick = function (event) {
|
|
174
|
-
|
|
175
|
-
event.preventDefault();
|
|
176
|
-
}
|
|
177
|
-
var onChange = _this.props.onChange;
|
|
178
|
-
var keyedFormData = _this.state.keyedFormData;
|
|
179
|
-
var newKeyedFormDataRow = {
|
|
180
|
-
key: generateRowId(),
|
|
181
|
-
item: _this._getNewFormDataRow()
|
|
182
|
-
};
|
|
183
|
-
var newKeyedFormData = [].concat(keyedFormData, [newKeyedFormDataRow]);
|
|
184
|
-
_this.setState({
|
|
185
|
-
keyedFormData: newKeyedFormData,
|
|
186
|
-
updatedKeyedFormData: true
|
|
187
|
-
}, function () {
|
|
188
|
-
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
189
|
-
});
|
|
174
|
+
_this._handleAddClick(event);
|
|
190
175
|
};
|
|
191
176
|
_this.onAddIndexClick = function (index) {
|
|
192
177
|
return function (event) {
|
|
193
|
-
|
|
194
|
-
event.preventDefault();
|
|
195
|
-
}
|
|
196
|
-
var onChange = _this.props.onChange;
|
|
197
|
-
var keyedFormData = _this.state.keyedFormData;
|
|
198
|
-
var newKeyedFormDataRow = {
|
|
199
|
-
key: generateRowId(),
|
|
200
|
-
item: _this._getNewFormDataRow()
|
|
201
|
-
};
|
|
202
|
-
var newKeyedFormData = [].concat(keyedFormData);
|
|
203
|
-
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
204
|
-
_this.setState({
|
|
205
|
-
keyedFormData: newKeyedFormData,
|
|
206
|
-
updatedKeyedFormData: true
|
|
207
|
-
}, function () {
|
|
208
|
-
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
209
|
-
});
|
|
178
|
+
_this._handleAddClick(event, index);
|
|
210
179
|
};
|
|
211
180
|
};
|
|
212
181
|
_this.onDropIndexClick = function (index) {
|
|
@@ -385,6 +354,42 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
385
354
|
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
386
355
|
* that the schema is fixed and allows additional items.
|
|
387
356
|
*/;
|
|
357
|
+
/** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
|
|
358
|
+
* either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
|
|
359
|
+
* the state, and then returning `onChange()` with the plain form data converted from the keyed data
|
|
360
|
+
*
|
|
361
|
+
* @param event - The event for the click
|
|
362
|
+
* @param [index] - The optional index at which to add the new data
|
|
363
|
+
*/
|
|
364
|
+
_proto._handleAddClick = function _handleAddClick(event, index) {
|
|
365
|
+
if (event) {
|
|
366
|
+
event.preventDefault();
|
|
367
|
+
}
|
|
368
|
+
var onChange = this.props.onChange;
|
|
369
|
+
var keyedFormData = this.state.keyedFormData;
|
|
370
|
+
var newKeyedFormDataRow = {
|
|
371
|
+
key: generateRowId(),
|
|
372
|
+
item: this._getNewFormDataRow()
|
|
373
|
+
};
|
|
374
|
+
var newKeyedFormData = [].concat(keyedFormData);
|
|
375
|
+
if (index !== undefined) {
|
|
376
|
+
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
377
|
+
} else {
|
|
378
|
+
newKeyedFormData.push(newKeyedFormDataRow);
|
|
379
|
+
}
|
|
380
|
+
this.setState({
|
|
381
|
+
keyedFormData: newKeyedFormData,
|
|
382
|
+
updatedKeyedFormData: true
|
|
383
|
+
}, function () {
|
|
384
|
+
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
388
|
+
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
389
|
+
* keyed data
|
|
390
|
+
*
|
|
391
|
+
* @param event - The event for the click
|
|
392
|
+
*/;
|
|
388
393
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
389
394
|
*/
|
|
390
395
|
_proto.render = function render() {
|
|
@@ -453,8 +458,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
453
458
|
var _schemaItems = isObject__default["default"](schema.items) ? schema.items : {};
|
|
454
459
|
var itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
455
460
|
var formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
461
|
+
var canAdd = this.canAddItem(formData);
|
|
456
462
|
var arrayProps = {
|
|
457
|
-
canAdd:
|
|
463
|
+
canAdd: canAdd,
|
|
458
464
|
items: keyedFormData.map(function (keyedItem, index) {
|
|
459
465
|
var key = keyedItem.key,
|
|
460
466
|
item = keyedItem.item;
|
|
@@ -468,6 +474,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
468
474
|
key: key,
|
|
469
475
|
index: index,
|
|
470
476
|
name: name && name + "-" + index,
|
|
477
|
+
canAdd: canAdd,
|
|
471
478
|
canMoveUp: index > 0,
|
|
472
479
|
canMoveDown: index < formData.length - 1,
|
|
473
480
|
itemSchema: itemSchema,
|
|
@@ -478,7 +485,8 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
478
485
|
autofocus: autofocus && index === 0,
|
|
479
486
|
onBlur: onBlur,
|
|
480
487
|
onFocus: onFocus,
|
|
481
|
-
rawErrors: rawErrors
|
|
488
|
+
rawErrors: rawErrors,
|
|
489
|
+
totalItems: keyedFormData.length
|
|
482
490
|
});
|
|
483
491
|
}),
|
|
484
492
|
className: "field field-array field-array-of-" + itemsSchema.type,
|
|
@@ -705,8 +713,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
705
713
|
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
706
714
|
}
|
|
707
715
|
// These are the props passed into the render function
|
|
716
|
+
var canAdd = this.canAddItem(items) && !!additionalSchema;
|
|
708
717
|
var arrayProps = {
|
|
709
|
-
canAdd:
|
|
718
|
+
canAdd: canAdd,
|
|
710
719
|
className: "field field-array field-array-fixed-items",
|
|
711
720
|
disabled: disabled,
|
|
712
721
|
idSchema: idSchema,
|
|
@@ -726,6 +735,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
726
735
|
key: key,
|
|
727
736
|
index: index,
|
|
728
737
|
name: name && name + "-" + index,
|
|
738
|
+
canAdd: canAdd,
|
|
729
739
|
canRemove: additional,
|
|
730
740
|
canMoveUp: index >= itemSchemas.length + 1,
|
|
731
741
|
canMoveDown: additional && index < items.length - 1,
|
|
@@ -737,7 +747,8 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
737
747
|
autofocus: autofocus && index === 0,
|
|
738
748
|
onBlur: onBlur,
|
|
739
749
|
onFocus: onFocus,
|
|
740
|
-
rawErrors: rawErrors
|
|
750
|
+
rawErrors: rawErrors,
|
|
751
|
+
totalItems: keyedFormData.length
|
|
741
752
|
});
|
|
742
753
|
}),
|
|
743
754
|
onAddClick: this.onAddClick,
|
|
@@ -762,6 +773,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
762
773
|
var key = props.key,
|
|
763
774
|
index = props.index,
|
|
764
775
|
name = props.name,
|
|
776
|
+
canAdd = props.canAdd,
|
|
765
777
|
_props$canRemove = props.canRemove,
|
|
766
778
|
canRemove = _props$canRemove === void 0 ? true : _props$canRemove,
|
|
767
779
|
_props$canMoveUp = props.canMoveUp,
|
|
@@ -776,7 +788,8 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
776
788
|
autofocus = props.autofocus,
|
|
777
789
|
onBlur = props.onBlur,
|
|
778
790
|
onFocus = props.onFocus,
|
|
779
|
-
rawErrors = props.rawErrors
|
|
791
|
+
rawErrors = props.rawErrors,
|
|
792
|
+
totalItems = props.totalItems;
|
|
780
793
|
var _this$props13 = this.props,
|
|
781
794
|
disabled = _this$props13.disabled,
|
|
782
795
|
hideError = _this$props13.hideError,
|
|
@@ -829,11 +842,13 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
829
842
|
}),
|
|
830
843
|
className: "array-item",
|
|
831
844
|
disabled: disabled,
|
|
845
|
+
canAdd: canAdd,
|
|
832
846
|
hasToolbar: has.toolbar,
|
|
833
847
|
hasMoveUp: has.moveUp,
|
|
834
848
|
hasMoveDown: has.moveDown,
|
|
835
849
|
hasRemove: has.remove,
|
|
836
850
|
index: index,
|
|
851
|
+
totalItems: totalItems,
|
|
837
852
|
key: key,
|
|
838
853
|
onAddIndexClick: this.onAddIndexClick,
|
|
839
854
|
onDropIndexClick: this.onDropIndexClick,
|
|
@@ -1906,17 +1921,20 @@ function ArrayFieldItemTemplate(props) {
|
|
|
1906
1921
|
style: btnStyle,
|
|
1907
1922
|
disabled: disabled || readonly || !hasMoveUp,
|
|
1908
1923
|
onClick: onReorderClick(index, index - 1),
|
|
1909
|
-
uiSchema: uiSchema
|
|
1924
|
+
uiSchema: uiSchema,
|
|
1925
|
+
registry: registry
|
|
1910
1926
|
}), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React__default["default"].createElement(MoveDownButton, {
|
|
1911
1927
|
style: btnStyle,
|
|
1912
1928
|
disabled: disabled || readonly || !hasMoveDown,
|
|
1913
1929
|
onClick: onReorderClick(index, index + 1),
|
|
1914
|
-
uiSchema: uiSchema
|
|
1930
|
+
uiSchema: uiSchema,
|
|
1931
|
+
registry: registry
|
|
1915
1932
|
}), hasRemove && /*#__PURE__*/React__default["default"].createElement(RemoveButton, {
|
|
1916
1933
|
style: btnStyle,
|
|
1917
1934
|
disabled: disabled || readonly,
|
|
1918
1935
|
onClick: onDropIndexClick(index),
|
|
1919
|
-
uiSchema: uiSchema
|
|
1936
|
+
uiSchema: uiSchema,
|
|
1937
|
+
registry: registry
|
|
1920
1938
|
}))));
|
|
1921
1939
|
}
|
|
1922
1940
|
|
|
@@ -1972,7 +1990,8 @@ function ArrayFieldTemplate(props) {
|
|
|
1972
1990
|
className: "array-item-add",
|
|
1973
1991
|
onClick: onAddClick,
|
|
1974
1992
|
disabled: disabled || readonly,
|
|
1975
|
-
uiSchema: uiSchema
|
|
1993
|
+
uiSchema: uiSchema,
|
|
1994
|
+
registry: registry
|
|
1976
1995
|
}));
|
|
1977
1996
|
}
|
|
1978
1997
|
|
|
@@ -2094,7 +2113,7 @@ function SubmitButton(_ref) {
|
|
|
2094
2113
|
}), submitText));
|
|
2095
2114
|
}
|
|
2096
2115
|
|
|
2097
|
-
var _excluded$2 = ["iconType", "icon", "className", "uiSchema"];
|
|
2116
|
+
var _excluded$2 = ["iconType", "icon", "className", "uiSchema", "registry"];
|
|
2098
2117
|
function IconButton(props) {
|
|
2099
2118
|
var _props$iconType = props.iconType,
|
|
2100
2119
|
iconType = _props$iconType === void 0 ? "default" : _props$iconType,
|
|
@@ -2139,7 +2158,8 @@ function RemoveButton(props) {
|
|
|
2139
2158
|
function AddButton(_ref) {
|
|
2140
2159
|
var className = _ref.className,
|
|
2141
2160
|
onClick = _ref.onClick,
|
|
2142
|
-
disabled = _ref.disabled
|
|
2161
|
+
disabled = _ref.disabled,
|
|
2162
|
+
registry = _ref.registry;
|
|
2143
2163
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2144
2164
|
className: "row"
|
|
2145
2165
|
}, /*#__PURE__*/React__default["default"].createElement("p", {
|
|
@@ -2150,7 +2170,8 @@ function AddButton(_ref) {
|
|
|
2150
2170
|
className: "btn-add col-xs-12",
|
|
2151
2171
|
title: "Add",
|
|
2152
2172
|
onClick: onClick,
|
|
2153
|
-
disabled: disabled
|
|
2173
|
+
disabled: disabled,
|
|
2174
|
+
registry: registry
|
|
2154
2175
|
})));
|
|
2155
2176
|
}
|
|
2156
2177
|
|
|
@@ -2353,7 +2374,8 @@ function ObjectFieldTemplate(props) {
|
|
|
2353
2374
|
className: "object-property-expand",
|
|
2354
2375
|
onClick: onAddClick(schema),
|
|
2355
2376
|
disabled: disabled || readonly,
|
|
2356
|
-
uiSchema: uiSchema
|
|
2377
|
+
uiSchema: uiSchema,
|
|
2378
|
+
registry: registry
|
|
2357
2379
|
}));
|
|
2358
2380
|
}
|
|
2359
2381
|
|
|
@@ -2445,7 +2467,8 @@ function WrapIfAdditionalTemplate(props) {
|
|
|
2445
2467
|
},
|
|
2446
2468
|
disabled: disabled || readonly,
|
|
2447
2469
|
onClick: onDropPropertyClick(label),
|
|
2448
|
-
uiSchema: uiSchema
|
|
2470
|
+
uiSchema: uiSchema,
|
|
2471
|
+
registry: registry
|
|
2449
2472
|
}))));
|
|
2450
2473
|
}
|
|
2451
2474
|
|
|
@@ -3583,9 +3606,10 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3583
3606
|
var schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
3584
3607
|
var _this$props3 = this.props,
|
|
3585
3608
|
customValidate = _this$props3.customValidate,
|
|
3586
|
-
transformErrors = _this$props3.transformErrors
|
|
3609
|
+
transformErrors = _this$props3.transformErrors,
|
|
3610
|
+
uiSchema = _this$props3.uiSchema;
|
|
3587
3611
|
var resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3588
|
-
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors);
|
|
3612
|
+
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
|
|
3589
3613
|
}
|
|
3590
3614
|
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */;
|
|
3591
3615
|
_proto.renderErrors = function renderErrors(registry) {
|
|
@@ -3754,7 +3778,8 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3754
3778
|
disabled: disabled,
|
|
3755
3779
|
readonly: readonly
|
|
3756
3780
|
}), children ? children : /*#__PURE__*/React__default["default"].createElement(SubmitButton, {
|
|
3757
|
-
uiSchema: uiSchema
|
|
3781
|
+
uiSchema: uiSchema,
|
|
3782
|
+
registry: registry
|
|
3758
3783
|
}), showErrorList === "bottom" && this.renderErrors(registry));
|
|
3759
3784
|
};
|
|
3760
3785
|
return Form;
|