@rjsf/core 5.4.0 → 5.5.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.
- package/dist/core.cjs.development.js +158 -49
- 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 +159 -50
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +158 -49
- 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/package.json +13 -12
|
@@ -147,6 +147,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
147
147
|
function ArrayField(props) {
|
|
148
148
|
var _this;
|
|
149
149
|
_this = _Component.call(this, props) || this;
|
|
150
|
+
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
151
|
+
* that the schema is fixed and allows additional items.
|
|
152
|
+
*/
|
|
150
153
|
_this._getNewFormDataRow = function () {
|
|
151
154
|
var _this$props = _this.props,
|
|
152
155
|
schema = _this$props.schema,
|
|
@@ -159,14 +162,32 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
159
162
|
// Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
|
|
160
163
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
161
164
|
};
|
|
165
|
+
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
166
|
+
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
167
|
+
* keyed data
|
|
168
|
+
*
|
|
169
|
+
* @param event - The event for the click
|
|
170
|
+
*/
|
|
162
171
|
_this.onAddClick = function (event) {
|
|
163
172
|
_this._handleAddClick(event);
|
|
164
173
|
};
|
|
174
|
+
/** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
|
|
175
|
+
* keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
|
|
176
|
+
* form data converted from the keyed data
|
|
177
|
+
*
|
|
178
|
+
* @param index - The index at which the add button is clicked
|
|
179
|
+
*/
|
|
165
180
|
_this.onAddIndexClick = function (index) {
|
|
166
181
|
return function (event) {
|
|
167
182
|
_this._handleAddClick(event, index);
|
|
168
183
|
};
|
|
169
184
|
};
|
|
185
|
+
/** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
|
|
186
|
+
* keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
|
|
187
|
+
* form data converted from the keyed data
|
|
188
|
+
*
|
|
189
|
+
* @param index - The index at which the copy button is clicked
|
|
190
|
+
*/
|
|
170
191
|
_this.onCopyIndexClick = function (index) {
|
|
171
192
|
return function (event) {
|
|
172
193
|
if (event) {
|
|
@@ -192,6 +213,12 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
192
213
|
});
|
|
193
214
|
};
|
|
194
215
|
};
|
|
216
|
+
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
217
|
+
* keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
|
|
218
|
+
* from the keyed data
|
|
219
|
+
*
|
|
220
|
+
* @param index - The index at which the remove button is clicked
|
|
221
|
+
*/
|
|
195
222
|
_this.onDropIndexClick = function (index) {
|
|
196
223
|
return function (event) {
|
|
197
224
|
if (event) {
|
|
@@ -225,6 +252,13 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
225
252
|
});
|
|
226
253
|
};
|
|
227
254
|
};
|
|
255
|
+
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
256
|
+
* row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
|
|
257
|
+
* plain form data converted from the keyed data
|
|
258
|
+
*
|
|
259
|
+
* @param index - The index of the item to move
|
|
260
|
+
* @param newIndex - The index to where the item is to be moved
|
|
261
|
+
*/
|
|
228
262
|
_this.onReorderClick = function (index, newIndex) {
|
|
229
263
|
return function (event) {
|
|
230
264
|
if (event) {
|
|
@@ -265,6 +299,11 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
265
299
|
});
|
|
266
300
|
};
|
|
267
301
|
};
|
|
302
|
+
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
303
|
+
* `onChange` callback with the updated form data
|
|
304
|
+
*
|
|
305
|
+
* @param index - The index of the item being changed
|
|
306
|
+
*/
|
|
268
307
|
_this.onChangeForIndex = function (index) {
|
|
269
308
|
return function (value, newErrorSchema, id) {
|
|
270
309
|
var _extends2;
|
|
@@ -282,6 +321,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
282
321
|
onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends2 = {}, _extends2[index] = newErrorSchema, _extends2)), id);
|
|
283
322
|
};
|
|
284
323
|
};
|
|
324
|
+
/** Callback handler used to change the value for a checkbox */
|
|
285
325
|
_this.onSelectChange = function (value) {
|
|
286
326
|
var _this$props5 = _this.props,
|
|
287
327
|
onChange = _this$props5.onChange,
|
|
@@ -365,10 +405,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
365
405
|
}
|
|
366
406
|
}
|
|
367
407
|
return addable;
|
|
368
|
-
}
|
|
369
|
-
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
370
|
-
* that the schema is fixed and allows additional items.
|
|
371
|
-
*/;
|
|
408
|
+
};
|
|
372
409
|
/** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
|
|
373
410
|
* either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
|
|
374
411
|
* the state, and then returning `onChange()` with the plain form data converted from the keyed data
|
|
@@ -398,13 +435,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
398
435
|
}, function () {
|
|
399
436
|
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
400
437
|
});
|
|
401
|
-
}
|
|
402
|
-
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
403
|
-
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
404
|
-
* keyed data
|
|
405
|
-
*
|
|
406
|
-
* @param event - The event for the click
|
|
407
|
-
*/;
|
|
438
|
+
};
|
|
408
439
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
409
440
|
*/
|
|
410
441
|
_proto.render = function render() {
|
|
@@ -1025,6 +1056,12 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
|
|
|
1025
1056
|
function AnyOfField(props) {
|
|
1026
1057
|
var _this;
|
|
1027
1058
|
_this = _Component.call(this, props) || this;
|
|
1059
|
+
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
1060
|
+
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
1061
|
+
* the `onChange` handler.
|
|
1062
|
+
*
|
|
1063
|
+
* @param option - The new option value being selected
|
|
1064
|
+
*/
|
|
1028
1065
|
_this.onOptionChange = function (option) {
|
|
1029
1066
|
var _this$state = _this.state,
|
|
1030
1067
|
selectedOption = _this$state.selectedOption,
|
|
@@ -1120,13 +1157,7 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
|
|
|
1120
1157
|
// If the form data matches none of the options, use the currently selected
|
|
1121
1158
|
// option, assuming it's available; otherwise use the first option
|
|
1122
1159
|
return selectedOption || 0;
|
|
1123
|
-
}
|
|
1124
|
-
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
1125
|
-
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
1126
|
-
* the `onChange` handler.
|
|
1127
|
-
*
|
|
1128
|
-
* @param option - The new option value being selected
|
|
1129
|
-
*/;
|
|
1160
|
+
};
|
|
1130
1161
|
_proto.getFieldId = function getFieldId() {
|
|
1131
1162
|
var _this$props4 = this.props,
|
|
1132
1163
|
idSchema = _this$props4.idSchema,
|
|
@@ -1313,10 +1344,19 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1313
1344
|
args[_key] = arguments[_key];
|
|
1314
1345
|
}
|
|
1315
1346
|
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
1347
|
+
/** Set up the initial state */
|
|
1316
1348
|
_this.state = {
|
|
1317
1349
|
wasPropertyKeyModified: false,
|
|
1318
1350
|
additionalProperties: {}
|
|
1319
1351
|
};
|
|
1352
|
+
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
1353
|
+
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
1354
|
+
* formData.
|
|
1355
|
+
*
|
|
1356
|
+
* @param name - The name of the property
|
|
1357
|
+
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1358
|
+
* @returns - The onPropertyChange callback for the `name` property
|
|
1359
|
+
*/
|
|
1320
1360
|
_this.onPropertyChange = function (name, addedByAdditionalProperties) {
|
|
1321
1361
|
if (addedByAdditionalProperties === void 0) {
|
|
1322
1362
|
addedByAdditionalProperties = false;
|
|
@@ -1341,6 +1381,12 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1341
1381
|
onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends3 = {}, _extends3[name] = newErrorSchema, _extends3)), id);
|
|
1342
1382
|
};
|
|
1343
1383
|
};
|
|
1384
|
+
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
1385
|
+
* and calls the `onChange` callback with it
|
|
1386
|
+
*
|
|
1387
|
+
* @param key - The key for which the drop callback is desired
|
|
1388
|
+
* @returns - The drop property click callback
|
|
1389
|
+
*/
|
|
1344
1390
|
_this.onDropPropertyClick = function (key) {
|
|
1345
1391
|
return function (event) {
|
|
1346
1392
|
event.preventDefault();
|
|
@@ -1352,6 +1398,13 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1352
1398
|
onChange(copiedFormData);
|
|
1353
1399
|
};
|
|
1354
1400
|
};
|
|
1401
|
+
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
1402
|
+
* that is already not assigned is found.
|
|
1403
|
+
*
|
|
1404
|
+
* @param preferredKey - The preferred name of a new key
|
|
1405
|
+
* @param [formData] - The form data in which to check if the desired key already exists
|
|
1406
|
+
* @returns - The name of the next available key from `preferredKey`
|
|
1407
|
+
*/
|
|
1355
1408
|
_this.getAvailableKey = function (preferredKey, formData) {
|
|
1356
1409
|
var _this$props3 = _this.props,
|
|
1357
1410
|
uiSchema = _this$props3.uiSchema,
|
|
@@ -1366,6 +1419,12 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1366
1419
|
}
|
|
1367
1420
|
return newKey;
|
|
1368
1421
|
};
|
|
1422
|
+
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
1423
|
+
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
1424
|
+
*
|
|
1425
|
+
* @param oldValue - The old value of a field
|
|
1426
|
+
* @returns - The key change callback function
|
|
1427
|
+
*/
|
|
1369
1428
|
_this.onKeyChange = function (oldValue) {
|
|
1370
1429
|
return function (value, newErrorSchema) {
|
|
1371
1430
|
var _newKeys, _extends4;
|
|
@@ -1391,6 +1450,11 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1391
1450
|
onChange(renamedObj, errorSchema && errorSchema && _extends({}, errorSchema, (_extends4 = {}, _extends4[value] = newErrorSchema, _extends4)));
|
|
1392
1451
|
};
|
|
1393
1452
|
};
|
|
1453
|
+
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
1454
|
+
* default data for that field has been added to the formData.
|
|
1455
|
+
*
|
|
1456
|
+
* @param schema - The schema element to which the new property is being added
|
|
1457
|
+
*/
|
|
1394
1458
|
_this.handleAddClick = function (schema) {
|
|
1395
1459
|
return function () {
|
|
1396
1460
|
if (!schema.additionalProperties) {
|
|
@@ -1433,15 +1497,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1433
1497
|
_proto.isRequired = function isRequired(name) {
|
|
1434
1498
|
var schema = this.props.schema;
|
|
1435
1499
|
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
1436
|
-
}
|
|
1437
|
-
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
1438
|
-
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
1439
|
-
* formData.
|
|
1440
|
-
*
|
|
1441
|
-
* @param name - The name of the property
|
|
1442
|
-
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1443
|
-
* @returns - The onPropertyChange callback for the `name` property
|
|
1444
|
-
*/;
|
|
1500
|
+
};
|
|
1445
1501
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
1446
1502
|
*
|
|
1447
1503
|
* @param type - The type of the new additional schema property
|
|
@@ -1464,12 +1520,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1464
1520
|
// We don't have a datatype for some reason (perhaps additionalProperties was true)
|
|
1465
1521
|
return translateString(utils.TranslatableString.NewStringDefault);
|
|
1466
1522
|
}
|
|
1467
|
-
}
|
|
1468
|
-
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
1469
|
-
* default data for that field has been added to the formData.
|
|
1470
|
-
*
|
|
1471
|
-
* @param schema - The schema element to which the new property is being added
|
|
1472
|
-
*/;
|
|
1523
|
+
};
|
|
1473
1524
|
/** Renders the `ObjectField` from the given props
|
|
1474
1525
|
*/
|
|
1475
1526
|
_proto.render = function render() {
|
|
@@ -1573,6 +1624,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1573
1624
|
required: required,
|
|
1574
1625
|
idSchema: idSchema,
|
|
1575
1626
|
uiSchema: uiSchema,
|
|
1627
|
+
errorSchema: errorSchema,
|
|
1576
1628
|
schema: schema,
|
|
1577
1629
|
formData: formData,
|
|
1578
1630
|
formContext: formContext,
|
|
@@ -2137,7 +2189,7 @@ function ArrayFieldTitleTemplate(props) {
|
|
|
2137
2189
|
});
|
|
2138
2190
|
}
|
|
2139
2191
|
|
|
2140
|
-
var _excluded$3 = ["id", "name", "value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "onChange", "onChangeOverride", "options", "schema", "uiSchema", "formContext", "registry", "rawErrors", "type"];
|
|
2192
|
+
var _excluded$3 = ["id", "name", "value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "onChange", "onChangeOverride", "options", "schema", "uiSchema", "formContext", "registry", "rawErrors", "type", "hideLabel", "hideError"];
|
|
2141
2193
|
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
2142
2194
|
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
2143
2195
|
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
@@ -2225,7 +2277,7 @@ function SubmitButton(_ref) {
|
|
|
2225
2277
|
children: jsxRuntime.jsx("button", _extends({
|
|
2226
2278
|
type: 'submit'
|
|
2227
2279
|
}, submitButtonProps, {
|
|
2228
|
-
className: "btn btn-info " + submitButtonProps.className,
|
|
2280
|
+
className: "btn btn-info " + (submitButtonProps.className || ''),
|
|
2229
2281
|
children: submitText
|
|
2230
2282
|
}))
|
|
2231
2283
|
});
|
|
@@ -3211,6 +3263,7 @@ function extractFileInfo(dataURLs) {
|
|
|
3211
3263
|
function FileWidget(props) {
|
|
3212
3264
|
var disabled = props.disabled,
|
|
3213
3265
|
readonly = props.readonly,
|
|
3266
|
+
required = props.required,
|
|
3214
3267
|
multiple = props.multiple,
|
|
3215
3268
|
onChange = props.onChange,
|
|
3216
3269
|
value = props.value,
|
|
@@ -3243,6 +3296,7 @@ function FileWidget(props) {
|
|
|
3243
3296
|
children: [jsxRuntime.jsx(BaseInputTemplate, _extends({}, props, {
|
|
3244
3297
|
disabled: disabled || readonly,
|
|
3245
3298
|
type: 'file',
|
|
3299
|
+
required: value ? false : required,
|
|
3246
3300
|
onChangeOverride: handleChange,
|
|
3247
3301
|
value: '',
|
|
3248
3302
|
accept: options.accept ? String(options.accept) : undefined
|
|
@@ -3300,8 +3354,6 @@ function RadioWidget(_ref) {
|
|
|
3300
3354
|
onFocus = _ref.onFocus,
|
|
3301
3355
|
onChange = _ref.onChange,
|
|
3302
3356
|
id = _ref.id;
|
|
3303
|
-
// Generating a unique field name to identify this set of radio buttons
|
|
3304
|
-
var name = Math.random().toString();
|
|
3305
3357
|
var enumOptions = options.enumOptions,
|
|
3306
3358
|
enumDisabled = options.enumDisabled,
|
|
3307
3359
|
inline = options.inline,
|
|
@@ -3329,7 +3381,7 @@ function RadioWidget(_ref) {
|
|
|
3329
3381
|
type: 'radio',
|
|
3330
3382
|
id: utils.optionId(id, i),
|
|
3331
3383
|
checked: checked,
|
|
3332
|
-
name:
|
|
3384
|
+
name: id,
|
|
3333
3385
|
required: required,
|
|
3334
3386
|
value: String(i),
|
|
3335
3387
|
disabled: disabled || itemDisabled || readonly,
|
|
@@ -3602,10 +3654,6 @@ function getDefaultRegistry() {
|
|
|
3602
3654
|
/** The `Form` component renders the outer form and all the fields defined in the `schema` */
|
|
3603
3655
|
var Form = /*#__PURE__*/function (_Component) {
|
|
3604
3656
|
_inheritsLoose(Form, _Component);
|
|
3605
|
-
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
3606
|
-
* provide any possible type here
|
|
3607
|
-
*/
|
|
3608
|
-
|
|
3609
3657
|
/** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
|
|
3610
3658
|
* `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
|
|
3611
3659
|
* state construction.
|
|
@@ -3615,7 +3663,15 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3615
3663
|
function Form(props) {
|
|
3616
3664
|
var _this;
|
|
3617
3665
|
_this = _Component.call(this, props) || this;
|
|
3666
|
+
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
3667
|
+
* provide any possible type here
|
|
3668
|
+
*/
|
|
3618
3669
|
_this.formElement = void 0;
|
|
3670
|
+
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
3671
|
+
*
|
|
3672
|
+
* @param formData - The data for the `Form`
|
|
3673
|
+
* @param fields - The fields to keep while filtering
|
|
3674
|
+
*/
|
|
3619
3675
|
_this.getUsedFormData = function (formData, fields) {
|
|
3620
3676
|
// For the case of a single input form
|
|
3621
3677
|
if (fields.length === 0 && typeof formData !== 'object') {
|
|
@@ -3630,6 +3686,11 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3630
3686
|
}
|
|
3631
3687
|
return data;
|
|
3632
3688
|
};
|
|
3689
|
+
/** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
|
|
3690
|
+
*
|
|
3691
|
+
* @param pathSchema - The `PathSchema` object for the form
|
|
3692
|
+
* @param [formData] - The form data to use while checking for empty objects/arrays
|
|
3693
|
+
*/
|
|
3633
3694
|
_this.getFieldNames = function (pathSchema, formData) {
|
|
3634
3695
|
var getAllPaths = function getAllPaths(_obj, acc, paths) {
|
|
3635
3696
|
if (acc === void 0) {
|
|
@@ -3664,6 +3725,17 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3664
3725
|
};
|
|
3665
3726
|
return getAllPaths(pathSchema);
|
|
3666
3727
|
};
|
|
3728
|
+
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
3729
|
+
* `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
|
|
3730
|
+
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filterer to remove any extra data not
|
|
3731
|
+
* in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
|
|
3732
|
+
* updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
|
|
3733
|
+
* callback will be called if specified with the updated state.
|
|
3734
|
+
*
|
|
3735
|
+
* @param formData - The new form data from a change to a field
|
|
3736
|
+
* @param newErrorSchema - The new `ErrorSchema` based on the field change
|
|
3737
|
+
* @param id - The id of the field that caused the change
|
|
3738
|
+
*/
|
|
3667
3739
|
_this.onChange = function (formData, newErrorSchema, id) {
|
|
3668
3740
|
var _this$props = _this.props,
|
|
3669
3741
|
extraErrors = _this$props.extraErrors,
|
|
@@ -3724,6 +3796,12 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3724
3796
|
return onChange && onChange(_extends({}, _this.state, state), id);
|
|
3725
3797
|
});
|
|
3726
3798
|
};
|
|
3799
|
+
/**
|
|
3800
|
+
* Callback function to handle reset form data.
|
|
3801
|
+
* - Reset all fields with default values.
|
|
3802
|
+
* - Reset validations and errors
|
|
3803
|
+
*
|
|
3804
|
+
*/
|
|
3727
3805
|
_this.reset = function () {
|
|
3728
3806
|
var onChange = _this.props.onChange;
|
|
3729
3807
|
var newState = _this.getStateFromProps(_this.props, undefined);
|
|
@@ -3739,18 +3817,38 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3739
3817
|
return onChange && onChange(_extends({}, _this.state, state));
|
|
3740
3818
|
});
|
|
3741
3819
|
};
|
|
3820
|
+
/** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
|
|
3821
|
+
* was provided.
|
|
3822
|
+
*
|
|
3823
|
+
* @param id - The unique `id` of the field that was blurred
|
|
3824
|
+
* @param data - The data associated with the field that was blurred
|
|
3825
|
+
*/
|
|
3742
3826
|
_this.onBlur = function (id, data) {
|
|
3743
3827
|
var onBlur = _this.props.onBlur;
|
|
3744
3828
|
if (onBlur) {
|
|
3745
3829
|
onBlur(id, data);
|
|
3746
3830
|
}
|
|
3747
3831
|
};
|
|
3832
|
+
/** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
|
|
3833
|
+
* was provided.
|
|
3834
|
+
*
|
|
3835
|
+
* @param id - The unique `id` of the field that was focused
|
|
3836
|
+
* @param data - The data associated with the field that was focused
|
|
3837
|
+
*/
|
|
3748
3838
|
_this.onFocus = function (id, data) {
|
|
3749
3839
|
var onFocus = _this.props.onFocus;
|
|
3750
3840
|
if (onFocus) {
|
|
3751
3841
|
onFocus(id, data);
|
|
3752
3842
|
}
|
|
3753
3843
|
};
|
|
3844
|
+
/** Callback function to handle when the form is submitted. First, it prevents the default event behavior. Nothing
|
|
3845
|
+
* happens if the target and currentTarget of the event are not the same. It will omit any extra data in the
|
|
3846
|
+
* `formData` in the state if `omitExtraData` is true. It will validate the resulting `formData`, reporting errors
|
|
3847
|
+
* via the `onError()` callback unless validation is disabled. Finally it will add in any `extraErrors` and then call
|
|
3848
|
+
* back the `onSubmit` callback if it was provided.
|
|
3849
|
+
*
|
|
3850
|
+
* @param event - The submit HTML form event
|
|
3851
|
+
*/
|
|
3754
3852
|
_this.onSubmit = function (event) {
|
|
3755
3853
|
event.preventDefault();
|
|
3756
3854
|
if (event.target !== event.currentTarget) {
|
|
@@ -3943,12 +4041,7 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3943
4041
|
});
|
|
3944
4042
|
}
|
|
3945
4043
|
return null;
|
|
3946
|
-
}
|
|
3947
|
-
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
3948
|
-
*
|
|
3949
|
-
* @param formData - The data for the `Form`
|
|
3950
|
-
* @param fields - The fields to keep while filtering
|
|
3951
|
-
*/;
|
|
4044
|
+
};
|
|
3952
4045
|
/** Returns the registry for the form */
|
|
3953
4046
|
_proto.getRegistry = function getRegistry() {
|
|
3954
4047
|
var _this$props$templates;
|
|
@@ -4012,6 +4105,10 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4012
4105
|
// if not an exact match, try finding an input starting with the element id (like radio buttons or checkboxes)
|
|
4013
4106
|
field = this.formElement.current.querySelector("input[id^=" + elementId);
|
|
4014
4107
|
}
|
|
4108
|
+
if (field.length) {
|
|
4109
|
+
// If we got a list with length > 0
|
|
4110
|
+
field = field[0];
|
|
4111
|
+
}
|
|
4015
4112
|
if (field) {
|
|
4016
4113
|
field.focus();
|
|
4017
4114
|
}
|
|
@@ -4062,6 +4159,7 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4062
4159
|
* needed along with the submit button or any children of the form.
|
|
4063
4160
|
*/;
|
|
4064
4161
|
_proto.render = function render() {
|
|
4162
|
+
var _UI_OPTIONS_KEY, _submitUiSchema;
|
|
4065
4163
|
var _this$props7 = this.props,
|
|
4066
4164
|
children = _this$props7.children,
|
|
4067
4165
|
id = _this$props7.id,
|
|
@@ -4101,6 +4199,17 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4101
4199
|
// NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
|
|
4102
4200
|
var as = _internalFormWrapper ? tagName : undefined;
|
|
4103
4201
|
var FormTag = _internalFormWrapper || tagName || 'form';
|
|
4202
|
+
var _getUiOptions = utils.getUiOptions(uiSchema),
|
|
4203
|
+
_getUiOptions$SUBMIT_ = _getUiOptions[utils.SUBMIT_BTN_OPTIONS_KEY],
|
|
4204
|
+
submitOptions = _getUiOptions$SUBMIT_ === void 0 ? {} : _getUiOptions$SUBMIT_;
|
|
4205
|
+
if (disabled) {
|
|
4206
|
+
submitOptions = _extends({}, submitOptions, {
|
|
4207
|
+
props: _extends({}, submitOptions.props, {
|
|
4208
|
+
disabled: true
|
|
4209
|
+
})
|
|
4210
|
+
});
|
|
4211
|
+
}
|
|
4212
|
+
var submitUiSchema = (_submitUiSchema = {}, _submitUiSchema[utils.UI_OPTIONS_KEY] = (_UI_OPTIONS_KEY = {}, _UI_OPTIONS_KEY[utils.SUBMIT_BTN_OPTIONS_KEY] = submitOptions, _UI_OPTIONS_KEY), _submitUiSchema);
|
|
4104
4213
|
return jsxRuntime.jsxs(FormTag, {
|
|
4105
4214
|
className: className ? className : 'rjsf',
|
|
4106
4215
|
id: id,
|
|
@@ -4132,7 +4241,7 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4132
4241
|
disabled: disabled,
|
|
4133
4242
|
readonly: readonly
|
|
4134
4243
|
}), children ? children : jsxRuntime.jsx(SubmitButton, {
|
|
4135
|
-
uiSchema:
|
|
4244
|
+
uiSchema: submitUiSchema,
|
|
4136
4245
|
registry: registry
|
|
4137
4246
|
}), showErrorList === 'bottom' && this.renderErrors(registry)]
|
|
4138
4247
|
});
|