@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
package/dist/core.esm.js
CHANGED
|
@@ -155,42 +155,11 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
155
155
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
156
156
|
};
|
|
157
157
|
_this.onAddClick = function (event) {
|
|
158
|
-
|
|
159
|
-
event.preventDefault();
|
|
160
|
-
}
|
|
161
|
-
var onChange = _this.props.onChange;
|
|
162
|
-
var keyedFormData = _this.state.keyedFormData;
|
|
163
|
-
var newKeyedFormDataRow = {
|
|
164
|
-
key: generateRowId(),
|
|
165
|
-
item: _this._getNewFormDataRow()
|
|
166
|
-
};
|
|
167
|
-
var newKeyedFormData = [].concat(keyedFormData, [newKeyedFormDataRow]);
|
|
168
|
-
_this.setState({
|
|
169
|
-
keyedFormData: newKeyedFormData,
|
|
170
|
-
updatedKeyedFormData: true
|
|
171
|
-
}, function () {
|
|
172
|
-
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
173
|
-
});
|
|
158
|
+
_this._handleAddClick(event);
|
|
174
159
|
};
|
|
175
160
|
_this.onAddIndexClick = function (index) {
|
|
176
161
|
return function (event) {
|
|
177
|
-
|
|
178
|
-
event.preventDefault();
|
|
179
|
-
}
|
|
180
|
-
var onChange = _this.props.onChange;
|
|
181
|
-
var keyedFormData = _this.state.keyedFormData;
|
|
182
|
-
var newKeyedFormDataRow = {
|
|
183
|
-
key: generateRowId(),
|
|
184
|
-
item: _this._getNewFormDataRow()
|
|
185
|
-
};
|
|
186
|
-
var newKeyedFormData = [].concat(keyedFormData);
|
|
187
|
-
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
188
|
-
_this.setState({
|
|
189
|
-
keyedFormData: newKeyedFormData,
|
|
190
|
-
updatedKeyedFormData: true
|
|
191
|
-
}, function () {
|
|
192
|
-
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
193
|
-
});
|
|
162
|
+
_this._handleAddClick(event, index);
|
|
194
163
|
};
|
|
195
164
|
};
|
|
196
165
|
_this.onDropIndexClick = function (index) {
|
|
@@ -369,6 +338,42 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
369
338
|
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
370
339
|
* that the schema is fixed and allows additional items.
|
|
371
340
|
*/;
|
|
341
|
+
/** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
|
|
342
|
+
* either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
|
|
343
|
+
* the state, and then returning `onChange()` with the plain form data converted from the keyed data
|
|
344
|
+
*
|
|
345
|
+
* @param event - The event for the click
|
|
346
|
+
* @param [index] - The optional index at which to add the new data
|
|
347
|
+
*/
|
|
348
|
+
_proto._handleAddClick = function _handleAddClick(event, index) {
|
|
349
|
+
if (event) {
|
|
350
|
+
event.preventDefault();
|
|
351
|
+
}
|
|
352
|
+
var onChange = this.props.onChange;
|
|
353
|
+
var keyedFormData = this.state.keyedFormData;
|
|
354
|
+
var newKeyedFormDataRow = {
|
|
355
|
+
key: generateRowId(),
|
|
356
|
+
item: this._getNewFormDataRow()
|
|
357
|
+
};
|
|
358
|
+
var newKeyedFormData = [].concat(keyedFormData);
|
|
359
|
+
if (index !== undefined) {
|
|
360
|
+
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
361
|
+
} else {
|
|
362
|
+
newKeyedFormData.push(newKeyedFormDataRow);
|
|
363
|
+
}
|
|
364
|
+
this.setState({
|
|
365
|
+
keyedFormData: newKeyedFormData,
|
|
366
|
+
updatedKeyedFormData: true
|
|
367
|
+
}, function () {
|
|
368
|
+
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
372
|
+
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
373
|
+
* keyed data
|
|
374
|
+
*
|
|
375
|
+
* @param event - The event for the click
|
|
376
|
+
*/;
|
|
372
377
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
373
378
|
*/
|
|
374
379
|
_proto.render = function render() {
|
|
@@ -437,8 +442,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
437
442
|
var _schemaItems = isObject(schema.items) ? schema.items : {};
|
|
438
443
|
var itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
439
444
|
var formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
445
|
+
var canAdd = this.canAddItem(formData);
|
|
440
446
|
var arrayProps = {
|
|
441
|
-
canAdd:
|
|
447
|
+
canAdd: canAdd,
|
|
442
448
|
items: keyedFormData.map(function (keyedItem, index) {
|
|
443
449
|
var key = keyedItem.key,
|
|
444
450
|
item = keyedItem.item;
|
|
@@ -452,6 +458,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
452
458
|
key: key,
|
|
453
459
|
index: index,
|
|
454
460
|
name: name && name + "-" + index,
|
|
461
|
+
canAdd: canAdd,
|
|
455
462
|
canMoveUp: index > 0,
|
|
456
463
|
canMoveDown: index < formData.length - 1,
|
|
457
464
|
itemSchema: itemSchema,
|
|
@@ -462,7 +469,8 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
462
469
|
autofocus: autofocus && index === 0,
|
|
463
470
|
onBlur: onBlur,
|
|
464
471
|
onFocus: onFocus,
|
|
465
|
-
rawErrors: rawErrors
|
|
472
|
+
rawErrors: rawErrors,
|
|
473
|
+
totalItems: keyedFormData.length
|
|
466
474
|
});
|
|
467
475
|
}),
|
|
468
476
|
className: "field field-array field-array-of-" + itemsSchema.type,
|
|
@@ -689,8 +697,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
689
697
|
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
690
698
|
}
|
|
691
699
|
// These are the props passed into the render function
|
|
700
|
+
var canAdd = this.canAddItem(items) && !!additionalSchema;
|
|
692
701
|
var arrayProps = {
|
|
693
|
-
canAdd:
|
|
702
|
+
canAdd: canAdd,
|
|
694
703
|
className: "field field-array field-array-fixed-items",
|
|
695
704
|
disabled: disabled,
|
|
696
705
|
idSchema: idSchema,
|
|
@@ -710,6 +719,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
710
719
|
key: key,
|
|
711
720
|
index: index,
|
|
712
721
|
name: name && name + "-" + index,
|
|
722
|
+
canAdd: canAdd,
|
|
713
723
|
canRemove: additional,
|
|
714
724
|
canMoveUp: index >= itemSchemas.length + 1,
|
|
715
725
|
canMoveDown: additional && index < items.length - 1,
|
|
@@ -721,7 +731,8 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
721
731
|
autofocus: autofocus && index === 0,
|
|
722
732
|
onBlur: onBlur,
|
|
723
733
|
onFocus: onFocus,
|
|
724
|
-
rawErrors: rawErrors
|
|
734
|
+
rawErrors: rawErrors,
|
|
735
|
+
totalItems: keyedFormData.length
|
|
725
736
|
});
|
|
726
737
|
}),
|
|
727
738
|
onAddClick: this.onAddClick,
|
|
@@ -746,6 +757,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
746
757
|
var key = props.key,
|
|
747
758
|
index = props.index,
|
|
748
759
|
name = props.name,
|
|
760
|
+
canAdd = props.canAdd,
|
|
749
761
|
_props$canRemove = props.canRemove,
|
|
750
762
|
canRemove = _props$canRemove === void 0 ? true : _props$canRemove,
|
|
751
763
|
_props$canMoveUp = props.canMoveUp,
|
|
@@ -760,7 +772,8 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
760
772
|
autofocus = props.autofocus,
|
|
761
773
|
onBlur = props.onBlur,
|
|
762
774
|
onFocus = props.onFocus,
|
|
763
|
-
rawErrors = props.rawErrors
|
|
775
|
+
rawErrors = props.rawErrors,
|
|
776
|
+
totalItems = props.totalItems;
|
|
764
777
|
var _this$props13 = this.props,
|
|
765
778
|
disabled = _this$props13.disabled,
|
|
766
779
|
hideError = _this$props13.hideError,
|
|
@@ -813,11 +826,13 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
813
826
|
}),
|
|
814
827
|
className: "array-item",
|
|
815
828
|
disabled: disabled,
|
|
829
|
+
canAdd: canAdd,
|
|
816
830
|
hasToolbar: has.toolbar,
|
|
817
831
|
hasMoveUp: has.moveUp,
|
|
818
832
|
hasMoveDown: has.moveDown,
|
|
819
833
|
hasRemove: has.remove,
|
|
820
834
|
index: index,
|
|
835
|
+
totalItems: totalItems,
|
|
821
836
|
key: key,
|
|
822
837
|
onAddIndexClick: this.onAddIndexClick,
|
|
823
838
|
onDropIndexClick: this.onDropIndexClick,
|
|
@@ -1890,17 +1905,20 @@ function ArrayFieldItemTemplate(props) {
|
|
|
1890
1905
|
style: btnStyle,
|
|
1891
1906
|
disabled: disabled || readonly || !hasMoveUp,
|
|
1892
1907
|
onClick: onReorderClick(index, index - 1),
|
|
1893
|
-
uiSchema: uiSchema
|
|
1908
|
+
uiSchema: uiSchema,
|
|
1909
|
+
registry: registry
|
|
1894
1910
|
}), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React.createElement(MoveDownButton, {
|
|
1895
1911
|
style: btnStyle,
|
|
1896
1912
|
disabled: disabled || readonly || !hasMoveDown,
|
|
1897
1913
|
onClick: onReorderClick(index, index + 1),
|
|
1898
|
-
uiSchema: uiSchema
|
|
1914
|
+
uiSchema: uiSchema,
|
|
1915
|
+
registry: registry
|
|
1899
1916
|
}), hasRemove && /*#__PURE__*/React.createElement(RemoveButton, {
|
|
1900
1917
|
style: btnStyle,
|
|
1901
1918
|
disabled: disabled || readonly,
|
|
1902
1919
|
onClick: onDropIndexClick(index),
|
|
1903
|
-
uiSchema: uiSchema
|
|
1920
|
+
uiSchema: uiSchema,
|
|
1921
|
+
registry: registry
|
|
1904
1922
|
}))));
|
|
1905
1923
|
}
|
|
1906
1924
|
|
|
@@ -1956,7 +1974,8 @@ function ArrayFieldTemplate(props) {
|
|
|
1956
1974
|
className: "array-item-add",
|
|
1957
1975
|
onClick: onAddClick,
|
|
1958
1976
|
disabled: disabled || readonly,
|
|
1959
|
-
uiSchema: uiSchema
|
|
1977
|
+
uiSchema: uiSchema,
|
|
1978
|
+
registry: registry
|
|
1960
1979
|
}));
|
|
1961
1980
|
}
|
|
1962
1981
|
|
|
@@ -2078,7 +2097,7 @@ function SubmitButton(_ref) {
|
|
|
2078
2097
|
}), submitText));
|
|
2079
2098
|
}
|
|
2080
2099
|
|
|
2081
|
-
var _excluded$2 = ["iconType", "icon", "className", "uiSchema"];
|
|
2100
|
+
var _excluded$2 = ["iconType", "icon", "className", "uiSchema", "registry"];
|
|
2082
2101
|
function IconButton(props) {
|
|
2083
2102
|
var _props$iconType = props.iconType,
|
|
2084
2103
|
iconType = _props$iconType === void 0 ? "default" : _props$iconType,
|
|
@@ -2123,7 +2142,8 @@ function RemoveButton(props) {
|
|
|
2123
2142
|
function AddButton(_ref) {
|
|
2124
2143
|
var className = _ref.className,
|
|
2125
2144
|
onClick = _ref.onClick,
|
|
2126
|
-
disabled = _ref.disabled
|
|
2145
|
+
disabled = _ref.disabled,
|
|
2146
|
+
registry = _ref.registry;
|
|
2127
2147
|
return /*#__PURE__*/React.createElement("div", {
|
|
2128
2148
|
className: "row"
|
|
2129
2149
|
}, /*#__PURE__*/React.createElement("p", {
|
|
@@ -2134,7 +2154,8 @@ function AddButton(_ref) {
|
|
|
2134
2154
|
className: "btn-add col-xs-12",
|
|
2135
2155
|
title: "Add",
|
|
2136
2156
|
onClick: onClick,
|
|
2137
|
-
disabled: disabled
|
|
2157
|
+
disabled: disabled,
|
|
2158
|
+
registry: registry
|
|
2138
2159
|
})));
|
|
2139
2160
|
}
|
|
2140
2161
|
|
|
@@ -2337,7 +2358,8 @@ function ObjectFieldTemplate(props) {
|
|
|
2337
2358
|
className: "object-property-expand",
|
|
2338
2359
|
onClick: onAddClick(schema),
|
|
2339
2360
|
disabled: disabled || readonly,
|
|
2340
|
-
uiSchema: uiSchema
|
|
2361
|
+
uiSchema: uiSchema,
|
|
2362
|
+
registry: registry
|
|
2341
2363
|
}));
|
|
2342
2364
|
}
|
|
2343
2365
|
|
|
@@ -2429,7 +2451,8 @@ function WrapIfAdditionalTemplate(props) {
|
|
|
2429
2451
|
},
|
|
2430
2452
|
disabled: disabled || readonly,
|
|
2431
2453
|
onClick: onDropPropertyClick(label),
|
|
2432
|
-
uiSchema: uiSchema
|
|
2454
|
+
uiSchema: uiSchema,
|
|
2455
|
+
registry: registry
|
|
2433
2456
|
}))));
|
|
2434
2457
|
}
|
|
2435
2458
|
|
|
@@ -3567,9 +3590,10 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3567
3590
|
var schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
3568
3591
|
var _this$props3 = this.props,
|
|
3569
3592
|
customValidate = _this$props3.customValidate,
|
|
3570
|
-
transformErrors = _this$props3.transformErrors
|
|
3593
|
+
transformErrors = _this$props3.transformErrors,
|
|
3594
|
+
uiSchema = _this$props3.uiSchema;
|
|
3571
3595
|
var resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3572
|
-
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors);
|
|
3596
|
+
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
|
|
3573
3597
|
}
|
|
3574
3598
|
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */;
|
|
3575
3599
|
_proto.renderErrors = function renderErrors(registry) {
|
|
@@ -3738,7 +3762,8 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3738
3762
|
disabled: disabled,
|
|
3739
3763
|
readonly: readonly
|
|
3740
3764
|
}), children ? children : /*#__PURE__*/React.createElement(SubmitButton, {
|
|
3741
|
-
uiSchema: uiSchema
|
|
3765
|
+
uiSchema: uiSchema,
|
|
3766
|
+
registry: registry
|
|
3742
3767
|
}), showErrorList === "bottom" && this.renderErrors(registry));
|
|
3743
3768
|
};
|
|
3744
3769
|
return Form;
|