@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
package/dist/core.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { Component, useState, useCallback, useEffect, useReducer, useMemo, createRef, forwardRef } from 'react';
|
|
3
|
-
import { isFixedItems, allowAdditionalItems, getUiOptions, ITEMS_KEY, getTemplate, TranslatableString, isCustomWidget, getWidget, optionsList, deepEquals, ERRORS_KEY, asNumber, REF_KEY, orderProperties, PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ANY_OF_KEY, ONE_OF_KEY, mergeObjects, UI_OPTIONS_KEY, descriptionId, getSchemaType, ID_KEY, hasWidget, titleId, getInputProps, examplesId, ariaDescribedByIds, getSubmitButtonOptions, errorId, helpId, canExpand, parseDateString, toDateString, pad, schemaRequiresTrueValue, labelValue, enumOptionsValueForIndex, enumOptionsIsSelected, optionId, enumOptionsSelectValue, enumOptionsDeselectValue, utcToLocal, localToUTC, dataURItoBlob, enumOptionsIndexForValue, englishStringTranslator, createSchemaUtils, shouldRender, UI_GLOBAL_OPTIONS_KEY, isObject as isObject$1, RJSF_ADDITONAL_PROPERTIES_FLAG, NAME_KEY } from '@rjsf/utils';
|
|
3
|
+
import { isFixedItems, allowAdditionalItems, getUiOptions, ITEMS_KEY, getTemplate, TranslatableString, isCustomWidget, getWidget, optionsList, deepEquals, ERRORS_KEY, asNumber, REF_KEY, orderProperties, PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ANY_OF_KEY, ONE_OF_KEY, mergeObjects, UI_OPTIONS_KEY, descriptionId, getSchemaType, ID_KEY, hasWidget, titleId, getInputProps, examplesId, ariaDescribedByIds, getSubmitButtonOptions, errorId, helpId, canExpand, parseDateString, toDateString, pad, schemaRequiresTrueValue, labelValue, enumOptionsValueForIndex, enumOptionsIsSelected, optionId, enumOptionsSelectValue, enumOptionsDeselectValue, utcToLocal, localToUTC, dataURItoBlob, enumOptionsIndexForValue, englishStringTranslator, createSchemaUtils, shouldRender, UI_GLOBAL_OPTIONS_KEY, SUBMIT_BTN_OPTIONS_KEY, isObject as isObject$1, RJSF_ADDITONAL_PROPERTIES_FLAG, NAME_KEY } from '@rjsf/utils';
|
|
4
4
|
import get from 'lodash-es/get';
|
|
5
5
|
import isEmpty from 'lodash-es/isEmpty';
|
|
6
6
|
import _pick from 'lodash-es/pick';
|
|
@@ -129,6 +129,9 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
129
129
|
function ArrayField(props) {
|
|
130
130
|
var _this;
|
|
131
131
|
_this = _Component.call(this, props) || this;
|
|
132
|
+
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
133
|
+
* that the schema is fixed and allows additional items.
|
|
134
|
+
*/
|
|
132
135
|
_this._getNewFormDataRow = function () {
|
|
133
136
|
var _this$props = _this.props,
|
|
134
137
|
schema = _this$props.schema,
|
|
@@ -141,14 +144,32 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
141
144
|
// Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
|
|
142
145
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
143
146
|
};
|
|
147
|
+
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
148
|
+
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
149
|
+
* keyed data
|
|
150
|
+
*
|
|
151
|
+
* @param event - The event for the click
|
|
152
|
+
*/
|
|
144
153
|
_this.onAddClick = function (event) {
|
|
145
154
|
_this._handleAddClick(event);
|
|
146
155
|
};
|
|
156
|
+
/** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
|
|
157
|
+
* keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
|
|
158
|
+
* form data converted from the keyed data
|
|
159
|
+
*
|
|
160
|
+
* @param index - The index at which the add button is clicked
|
|
161
|
+
*/
|
|
147
162
|
_this.onAddIndexClick = function (index) {
|
|
148
163
|
return function (event) {
|
|
149
164
|
_this._handleAddClick(event, index);
|
|
150
165
|
};
|
|
151
166
|
};
|
|
167
|
+
/** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
|
|
168
|
+
* keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
|
|
169
|
+
* form data converted from the keyed data
|
|
170
|
+
*
|
|
171
|
+
* @param index - The index at which the copy button is clicked
|
|
172
|
+
*/
|
|
152
173
|
_this.onCopyIndexClick = function (index) {
|
|
153
174
|
return function (event) {
|
|
154
175
|
if (event) {
|
|
@@ -174,6 +195,12 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
174
195
|
});
|
|
175
196
|
};
|
|
176
197
|
};
|
|
198
|
+
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
199
|
+
* keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
|
|
200
|
+
* from the keyed data
|
|
201
|
+
*
|
|
202
|
+
* @param index - The index at which the remove button is clicked
|
|
203
|
+
*/
|
|
177
204
|
_this.onDropIndexClick = function (index) {
|
|
178
205
|
return function (event) {
|
|
179
206
|
if (event) {
|
|
@@ -207,6 +234,13 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
207
234
|
});
|
|
208
235
|
};
|
|
209
236
|
};
|
|
237
|
+
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
238
|
+
* row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
|
|
239
|
+
* plain form data converted from the keyed data
|
|
240
|
+
*
|
|
241
|
+
* @param index - The index of the item to move
|
|
242
|
+
* @param newIndex - The index to where the item is to be moved
|
|
243
|
+
*/
|
|
210
244
|
_this.onReorderClick = function (index, newIndex) {
|
|
211
245
|
return function (event) {
|
|
212
246
|
if (event) {
|
|
@@ -247,6 +281,11 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
247
281
|
});
|
|
248
282
|
};
|
|
249
283
|
};
|
|
284
|
+
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
285
|
+
* `onChange` callback with the updated form data
|
|
286
|
+
*
|
|
287
|
+
* @param index - The index of the item being changed
|
|
288
|
+
*/
|
|
250
289
|
_this.onChangeForIndex = function (index) {
|
|
251
290
|
return function (value, newErrorSchema, id) {
|
|
252
291
|
var _extends2;
|
|
@@ -264,6 +303,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
264
303
|
onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends2 = {}, _extends2[index] = newErrorSchema, _extends2)), id);
|
|
265
304
|
};
|
|
266
305
|
};
|
|
306
|
+
/** Callback handler used to change the value for a checkbox */
|
|
267
307
|
_this.onSelectChange = function (value) {
|
|
268
308
|
var _this$props5 = _this.props,
|
|
269
309
|
onChange = _this$props5.onChange,
|
|
@@ -347,10 +387,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
347
387
|
}
|
|
348
388
|
}
|
|
349
389
|
return addable;
|
|
350
|
-
}
|
|
351
|
-
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
352
|
-
* that the schema is fixed and allows additional items.
|
|
353
|
-
*/;
|
|
390
|
+
};
|
|
354
391
|
/** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
|
|
355
392
|
* either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
|
|
356
393
|
* the state, and then returning `onChange()` with the plain form data converted from the keyed data
|
|
@@ -380,13 +417,7 @@ var ArrayField = /*#__PURE__*/function (_Component) {
|
|
|
380
417
|
}, function () {
|
|
381
418
|
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
382
419
|
});
|
|
383
|
-
}
|
|
384
|
-
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
385
|
-
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
386
|
-
* keyed data
|
|
387
|
-
*
|
|
388
|
-
* @param event - The event for the click
|
|
389
|
-
*/;
|
|
420
|
+
};
|
|
390
421
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
391
422
|
*/
|
|
392
423
|
_proto.render = function render() {
|
|
@@ -1007,6 +1038,12 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
|
|
|
1007
1038
|
function AnyOfField(props) {
|
|
1008
1039
|
var _this;
|
|
1009
1040
|
_this = _Component.call(this, props) || this;
|
|
1041
|
+
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
1042
|
+
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
1043
|
+
* the `onChange` handler.
|
|
1044
|
+
*
|
|
1045
|
+
* @param option - The new option value being selected
|
|
1046
|
+
*/
|
|
1010
1047
|
_this.onOptionChange = function (option) {
|
|
1011
1048
|
var _this$state = _this.state,
|
|
1012
1049
|
selectedOption = _this$state.selectedOption,
|
|
@@ -1102,13 +1139,7 @@ var AnyOfField = /*#__PURE__*/function (_Component) {
|
|
|
1102
1139
|
// If the form data matches none of the options, use the currently selected
|
|
1103
1140
|
// option, assuming it's available; otherwise use the first option
|
|
1104
1141
|
return selectedOption || 0;
|
|
1105
|
-
}
|
|
1106
|
-
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
1107
|
-
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
1108
|
-
* the `onChange` handler.
|
|
1109
|
-
*
|
|
1110
|
-
* @param option - The new option value being selected
|
|
1111
|
-
*/;
|
|
1142
|
+
};
|
|
1112
1143
|
_proto.getFieldId = function getFieldId() {
|
|
1113
1144
|
var _this$props4 = this.props,
|
|
1114
1145
|
idSchema = _this$props4.idSchema,
|
|
@@ -1295,10 +1326,19 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1295
1326
|
args[_key] = arguments[_key];
|
|
1296
1327
|
}
|
|
1297
1328
|
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
1329
|
+
/** Set up the initial state */
|
|
1298
1330
|
_this.state = {
|
|
1299
1331
|
wasPropertyKeyModified: false,
|
|
1300
1332
|
additionalProperties: {}
|
|
1301
1333
|
};
|
|
1334
|
+
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
1335
|
+
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
1336
|
+
* formData.
|
|
1337
|
+
*
|
|
1338
|
+
* @param name - The name of the property
|
|
1339
|
+
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1340
|
+
* @returns - The onPropertyChange callback for the `name` property
|
|
1341
|
+
*/
|
|
1302
1342
|
_this.onPropertyChange = function (name, addedByAdditionalProperties) {
|
|
1303
1343
|
if (addedByAdditionalProperties === void 0) {
|
|
1304
1344
|
addedByAdditionalProperties = false;
|
|
@@ -1323,6 +1363,12 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1323
1363
|
onChange(newFormData, errorSchema && errorSchema && _extends({}, errorSchema, (_extends3 = {}, _extends3[name] = newErrorSchema, _extends3)), id);
|
|
1324
1364
|
};
|
|
1325
1365
|
};
|
|
1366
|
+
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
1367
|
+
* and calls the `onChange` callback with it
|
|
1368
|
+
*
|
|
1369
|
+
* @param key - The key for which the drop callback is desired
|
|
1370
|
+
* @returns - The drop property click callback
|
|
1371
|
+
*/
|
|
1326
1372
|
_this.onDropPropertyClick = function (key) {
|
|
1327
1373
|
return function (event) {
|
|
1328
1374
|
event.preventDefault();
|
|
@@ -1334,6 +1380,13 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1334
1380
|
onChange(copiedFormData);
|
|
1335
1381
|
};
|
|
1336
1382
|
};
|
|
1383
|
+
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
1384
|
+
* that is already not assigned is found.
|
|
1385
|
+
*
|
|
1386
|
+
* @param preferredKey - The preferred name of a new key
|
|
1387
|
+
* @param [formData] - The form data in which to check if the desired key already exists
|
|
1388
|
+
* @returns - The name of the next available key from `preferredKey`
|
|
1389
|
+
*/
|
|
1337
1390
|
_this.getAvailableKey = function (preferredKey, formData) {
|
|
1338
1391
|
var _this$props3 = _this.props,
|
|
1339
1392
|
uiSchema = _this$props3.uiSchema,
|
|
@@ -1348,6 +1401,12 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1348
1401
|
}
|
|
1349
1402
|
return newKey;
|
|
1350
1403
|
};
|
|
1404
|
+
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
1405
|
+
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
1406
|
+
*
|
|
1407
|
+
* @param oldValue - The old value of a field
|
|
1408
|
+
* @returns - The key change callback function
|
|
1409
|
+
*/
|
|
1351
1410
|
_this.onKeyChange = function (oldValue) {
|
|
1352
1411
|
return function (value, newErrorSchema) {
|
|
1353
1412
|
var _newKeys, _extends4;
|
|
@@ -1373,6 +1432,11 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1373
1432
|
onChange(renamedObj, errorSchema && errorSchema && _extends({}, errorSchema, (_extends4 = {}, _extends4[value] = newErrorSchema, _extends4)));
|
|
1374
1433
|
};
|
|
1375
1434
|
};
|
|
1435
|
+
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
1436
|
+
* default data for that field has been added to the formData.
|
|
1437
|
+
*
|
|
1438
|
+
* @param schema - The schema element to which the new property is being added
|
|
1439
|
+
*/
|
|
1376
1440
|
_this.handleAddClick = function (schema) {
|
|
1377
1441
|
return function () {
|
|
1378
1442
|
if (!schema.additionalProperties) {
|
|
@@ -1415,15 +1479,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1415
1479
|
_proto.isRequired = function isRequired(name) {
|
|
1416
1480
|
var schema = this.props.schema;
|
|
1417
1481
|
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
1418
|
-
}
|
|
1419
|
-
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
1420
|
-
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
1421
|
-
* formData.
|
|
1422
|
-
*
|
|
1423
|
-
* @param name - The name of the property
|
|
1424
|
-
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1425
|
-
* @returns - The onPropertyChange callback for the `name` property
|
|
1426
|
-
*/;
|
|
1482
|
+
};
|
|
1427
1483
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
1428
1484
|
*
|
|
1429
1485
|
* @param type - The type of the new additional schema property
|
|
@@ -1446,12 +1502,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1446
1502
|
// We don't have a datatype for some reason (perhaps additionalProperties was true)
|
|
1447
1503
|
return translateString(TranslatableString.NewStringDefault);
|
|
1448
1504
|
}
|
|
1449
|
-
}
|
|
1450
|
-
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
1451
|
-
* default data for that field has been added to the formData.
|
|
1452
|
-
*
|
|
1453
|
-
* @param schema - The schema element to which the new property is being added
|
|
1454
|
-
*/;
|
|
1505
|
+
};
|
|
1455
1506
|
/** Renders the `ObjectField` from the given props
|
|
1456
1507
|
*/
|
|
1457
1508
|
_proto.render = function render() {
|
|
@@ -1555,6 +1606,7 @@ var ObjectField = /*#__PURE__*/function (_Component) {
|
|
|
1555
1606
|
required: required,
|
|
1556
1607
|
idSchema: idSchema,
|
|
1557
1608
|
uiSchema: uiSchema,
|
|
1609
|
+
errorSchema: errorSchema,
|
|
1558
1610
|
schema: schema,
|
|
1559
1611
|
formData: formData,
|
|
1560
1612
|
formContext: formContext,
|
|
@@ -2119,7 +2171,7 @@ function ArrayFieldTitleTemplate(props) {
|
|
|
2119
2171
|
});
|
|
2120
2172
|
}
|
|
2121
2173
|
|
|
2122
|
-
var _excluded$3 = ["id", "name", "value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "onChange", "onChangeOverride", "options", "schema", "uiSchema", "formContext", "registry", "rawErrors", "type"];
|
|
2174
|
+
var _excluded$3 = ["id", "name", "value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "onChange", "onChangeOverride", "options", "schema", "uiSchema", "formContext", "registry", "rawErrors", "type", "hideLabel", "hideError"];
|
|
2123
2175
|
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
2124
2176
|
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
2125
2177
|
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
@@ -2207,7 +2259,7 @@ function SubmitButton(_ref) {
|
|
|
2207
2259
|
children: jsx("button", _extends({
|
|
2208
2260
|
type: 'submit'
|
|
2209
2261
|
}, submitButtonProps, {
|
|
2210
|
-
className: "btn btn-info " + submitButtonProps.className,
|
|
2262
|
+
className: "btn btn-info " + (submitButtonProps.className || ''),
|
|
2211
2263
|
children: submitText
|
|
2212
2264
|
}))
|
|
2213
2265
|
});
|
|
@@ -3193,6 +3245,7 @@ function extractFileInfo(dataURLs) {
|
|
|
3193
3245
|
function FileWidget(props) {
|
|
3194
3246
|
var disabled = props.disabled,
|
|
3195
3247
|
readonly = props.readonly,
|
|
3248
|
+
required = props.required,
|
|
3196
3249
|
multiple = props.multiple,
|
|
3197
3250
|
onChange = props.onChange,
|
|
3198
3251
|
value = props.value,
|
|
@@ -3225,6 +3278,7 @@ function FileWidget(props) {
|
|
|
3225
3278
|
children: [jsx(BaseInputTemplate, _extends({}, props, {
|
|
3226
3279
|
disabled: disabled || readonly,
|
|
3227
3280
|
type: 'file',
|
|
3281
|
+
required: value ? false : required,
|
|
3228
3282
|
onChangeOverride: handleChange,
|
|
3229
3283
|
value: '',
|
|
3230
3284
|
accept: options.accept ? String(options.accept) : undefined
|
|
@@ -3282,8 +3336,6 @@ function RadioWidget(_ref) {
|
|
|
3282
3336
|
onFocus = _ref.onFocus,
|
|
3283
3337
|
onChange = _ref.onChange,
|
|
3284
3338
|
id = _ref.id;
|
|
3285
|
-
// Generating a unique field name to identify this set of radio buttons
|
|
3286
|
-
var name = Math.random().toString();
|
|
3287
3339
|
var enumOptions = options.enumOptions,
|
|
3288
3340
|
enumDisabled = options.enumDisabled,
|
|
3289
3341
|
inline = options.inline,
|
|
@@ -3311,7 +3363,7 @@ function RadioWidget(_ref) {
|
|
|
3311
3363
|
type: 'radio',
|
|
3312
3364
|
id: optionId(id, i),
|
|
3313
3365
|
checked: checked,
|
|
3314
|
-
name:
|
|
3366
|
+
name: id,
|
|
3315
3367
|
required: required,
|
|
3316
3368
|
value: String(i),
|
|
3317
3369
|
disabled: disabled || itemDisabled || readonly,
|
|
@@ -3584,10 +3636,6 @@ function getDefaultRegistry() {
|
|
|
3584
3636
|
/** The `Form` component renders the outer form and all the fields defined in the `schema` */
|
|
3585
3637
|
var Form = /*#__PURE__*/function (_Component) {
|
|
3586
3638
|
_inheritsLoose(Form, _Component);
|
|
3587
|
-
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
3588
|
-
* provide any possible type here
|
|
3589
|
-
*/
|
|
3590
|
-
|
|
3591
3639
|
/** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
|
|
3592
3640
|
* `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
|
|
3593
3641
|
* state construction.
|
|
@@ -3597,7 +3645,15 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3597
3645
|
function Form(props) {
|
|
3598
3646
|
var _this;
|
|
3599
3647
|
_this = _Component.call(this, props) || this;
|
|
3648
|
+
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
3649
|
+
* provide any possible type here
|
|
3650
|
+
*/
|
|
3600
3651
|
_this.formElement = void 0;
|
|
3652
|
+
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
3653
|
+
*
|
|
3654
|
+
* @param formData - The data for the `Form`
|
|
3655
|
+
* @param fields - The fields to keep while filtering
|
|
3656
|
+
*/
|
|
3601
3657
|
_this.getUsedFormData = function (formData, fields) {
|
|
3602
3658
|
// For the case of a single input form
|
|
3603
3659
|
if (fields.length === 0 && typeof formData !== 'object') {
|
|
@@ -3612,6 +3668,11 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3612
3668
|
}
|
|
3613
3669
|
return data;
|
|
3614
3670
|
};
|
|
3671
|
+
/** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
|
|
3672
|
+
*
|
|
3673
|
+
* @param pathSchema - The `PathSchema` object for the form
|
|
3674
|
+
* @param [formData] - The form data to use while checking for empty objects/arrays
|
|
3675
|
+
*/
|
|
3615
3676
|
_this.getFieldNames = function (pathSchema, formData) {
|
|
3616
3677
|
var getAllPaths = function getAllPaths(_obj, acc, paths) {
|
|
3617
3678
|
if (acc === void 0) {
|
|
@@ -3646,6 +3707,17 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3646
3707
|
};
|
|
3647
3708
|
return getAllPaths(pathSchema);
|
|
3648
3709
|
};
|
|
3710
|
+
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
3711
|
+
* `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
|
|
3712
|
+
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filterer to remove any extra data not
|
|
3713
|
+
* in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
|
|
3714
|
+
* updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
|
|
3715
|
+
* callback will be called if specified with the updated state.
|
|
3716
|
+
*
|
|
3717
|
+
* @param formData - The new form data from a change to a field
|
|
3718
|
+
* @param newErrorSchema - The new `ErrorSchema` based on the field change
|
|
3719
|
+
* @param id - The id of the field that caused the change
|
|
3720
|
+
*/
|
|
3649
3721
|
_this.onChange = function (formData, newErrorSchema, id) {
|
|
3650
3722
|
var _this$props = _this.props,
|
|
3651
3723
|
extraErrors = _this$props.extraErrors,
|
|
@@ -3706,6 +3778,12 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3706
3778
|
return onChange && onChange(_extends({}, _this.state, state), id);
|
|
3707
3779
|
});
|
|
3708
3780
|
};
|
|
3781
|
+
/**
|
|
3782
|
+
* Callback function to handle reset form data.
|
|
3783
|
+
* - Reset all fields with default values.
|
|
3784
|
+
* - Reset validations and errors
|
|
3785
|
+
*
|
|
3786
|
+
*/
|
|
3709
3787
|
_this.reset = function () {
|
|
3710
3788
|
var onChange = _this.props.onChange;
|
|
3711
3789
|
var newState = _this.getStateFromProps(_this.props, undefined);
|
|
@@ -3721,18 +3799,38 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3721
3799
|
return onChange && onChange(_extends({}, _this.state, state));
|
|
3722
3800
|
});
|
|
3723
3801
|
};
|
|
3802
|
+
/** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
|
|
3803
|
+
* was provided.
|
|
3804
|
+
*
|
|
3805
|
+
* @param id - The unique `id` of the field that was blurred
|
|
3806
|
+
* @param data - The data associated with the field that was blurred
|
|
3807
|
+
*/
|
|
3724
3808
|
_this.onBlur = function (id, data) {
|
|
3725
3809
|
var onBlur = _this.props.onBlur;
|
|
3726
3810
|
if (onBlur) {
|
|
3727
3811
|
onBlur(id, data);
|
|
3728
3812
|
}
|
|
3729
3813
|
};
|
|
3814
|
+
/** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
|
|
3815
|
+
* was provided.
|
|
3816
|
+
*
|
|
3817
|
+
* @param id - The unique `id` of the field that was focused
|
|
3818
|
+
* @param data - The data associated with the field that was focused
|
|
3819
|
+
*/
|
|
3730
3820
|
_this.onFocus = function (id, data) {
|
|
3731
3821
|
var onFocus = _this.props.onFocus;
|
|
3732
3822
|
if (onFocus) {
|
|
3733
3823
|
onFocus(id, data);
|
|
3734
3824
|
}
|
|
3735
3825
|
};
|
|
3826
|
+
/** Callback function to handle when the form is submitted. First, it prevents the default event behavior. Nothing
|
|
3827
|
+
* happens if the target and currentTarget of the event are not the same. It will omit any extra data in the
|
|
3828
|
+
* `formData` in the state if `omitExtraData` is true. It will validate the resulting `formData`, reporting errors
|
|
3829
|
+
* via the `onError()` callback unless validation is disabled. Finally it will add in any `extraErrors` and then call
|
|
3830
|
+
* back the `onSubmit` callback if it was provided.
|
|
3831
|
+
*
|
|
3832
|
+
* @param event - The submit HTML form event
|
|
3833
|
+
*/
|
|
3736
3834
|
_this.onSubmit = function (event) {
|
|
3737
3835
|
event.preventDefault();
|
|
3738
3836
|
if (event.target !== event.currentTarget) {
|
|
@@ -3925,12 +4023,7 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3925
4023
|
});
|
|
3926
4024
|
}
|
|
3927
4025
|
return null;
|
|
3928
|
-
}
|
|
3929
|
-
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
3930
|
-
*
|
|
3931
|
-
* @param formData - The data for the `Form`
|
|
3932
|
-
* @param fields - The fields to keep while filtering
|
|
3933
|
-
*/;
|
|
4026
|
+
};
|
|
3934
4027
|
/** Returns the registry for the form */
|
|
3935
4028
|
_proto.getRegistry = function getRegistry() {
|
|
3936
4029
|
var _this$props$templates;
|
|
@@ -3994,6 +4087,10 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
3994
4087
|
// if not an exact match, try finding an input starting with the element id (like radio buttons or checkboxes)
|
|
3995
4088
|
field = this.formElement.current.querySelector("input[id^=" + elementId);
|
|
3996
4089
|
}
|
|
4090
|
+
if (field.length) {
|
|
4091
|
+
// If we got a list with length > 0
|
|
4092
|
+
field = field[0];
|
|
4093
|
+
}
|
|
3997
4094
|
if (field) {
|
|
3998
4095
|
field.focus();
|
|
3999
4096
|
}
|
|
@@ -4044,6 +4141,7 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4044
4141
|
* needed along with the submit button or any children of the form.
|
|
4045
4142
|
*/;
|
|
4046
4143
|
_proto.render = function render() {
|
|
4144
|
+
var _UI_OPTIONS_KEY, _submitUiSchema;
|
|
4047
4145
|
var _this$props7 = this.props,
|
|
4048
4146
|
children = _this$props7.children,
|
|
4049
4147
|
id = _this$props7.id,
|
|
@@ -4083,6 +4181,17 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4083
4181
|
// NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
|
|
4084
4182
|
var as = _internalFormWrapper ? tagName : undefined;
|
|
4085
4183
|
var FormTag = _internalFormWrapper || tagName || 'form';
|
|
4184
|
+
var _getUiOptions = getUiOptions(uiSchema),
|
|
4185
|
+
_getUiOptions$SUBMIT_ = _getUiOptions[SUBMIT_BTN_OPTIONS_KEY],
|
|
4186
|
+
submitOptions = _getUiOptions$SUBMIT_ === void 0 ? {} : _getUiOptions$SUBMIT_;
|
|
4187
|
+
if (disabled) {
|
|
4188
|
+
submitOptions = _extends({}, submitOptions, {
|
|
4189
|
+
props: _extends({}, submitOptions.props, {
|
|
4190
|
+
disabled: true
|
|
4191
|
+
})
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
var submitUiSchema = (_submitUiSchema = {}, _submitUiSchema[UI_OPTIONS_KEY] = (_UI_OPTIONS_KEY = {}, _UI_OPTIONS_KEY[SUBMIT_BTN_OPTIONS_KEY] = submitOptions, _UI_OPTIONS_KEY), _submitUiSchema);
|
|
4086
4195
|
return jsxs(FormTag, {
|
|
4087
4196
|
className: className ? className : 'rjsf',
|
|
4088
4197
|
id: id,
|
|
@@ -4114,7 +4223,7 @@ var Form = /*#__PURE__*/function (_Component) {
|
|
|
4114
4223
|
disabled: disabled,
|
|
4115
4224
|
readonly: readonly
|
|
4116
4225
|
}), children ? children : jsx(SubmitButton, {
|
|
4117
|
-
uiSchema:
|
|
4226
|
+
uiSchema: submitUiSchema,
|
|
4118
4227
|
registry: registry
|
|
4119
4228
|
}), showErrorList === 'bottom' && this.renderErrors(registry)]
|
|
4120
4229
|
});
|