@luomus/laji-form 15.1.59 → 15.1.60

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.
@@ -269,7 +269,7 @@ class LajiForm extends React.Component {
269
269
  this.validateAndSubmit(warnings, onlySchema);
270
270
  }
271
271
  else if (valid) {
272
- onSubmit && onSubmit({ formData: this.memoizedFormContext.services.ids.removeLajiFormIds(formData) });
272
+ onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit({ formData: removeUndefinedFromArrays(this.memoizedFormContext.services.ids.removeLajiFormIds(formData)) });
273
273
  }
274
274
  else {
275
275
  onValidationError && onValidationError(this.state.extraErrors);
@@ -303,7 +303,7 @@ class LajiForm extends React.Component {
303
303
  liveValidations = {};
304
304
  }
305
305
  const schemaErrors = nonlive || onlySchema
306
- ? validator_ajv6_1.default.validateFormData(formData, this.props.schema, undefined, ((e) => validation_2.transformErrors(this.state.formContext.translations, e))).errorSchema
306
+ ? validator_ajv6_1.default.validateFormData(removeUndefinedFromArrays(formData), this.props.schema, undefined, ((e) => validation_2.transformErrors(this.state.formContext.translations, e))).errorSchema
307
307
  : {};
308
308
  block && this.memoizedFormContext.services.blocker.push();
309
309
  return new Promise(resolve => Promise.all([validation_1.default(validations, formData), validation_1.default(liveValidations, formData)]).then(([_validations, _liveValidations]) => {
@@ -639,3 +639,21 @@ LajiForm.defaultProps = {
639
639
  schema: {},
640
640
  uiSchema: {}
641
641
  };
642
+ const removeUndefinedFromArrays = (formData) => {
643
+ if (utils_1.isObject(formData)) {
644
+ return Object.keys(formData).reduce((obj, k) => {
645
+ obj[k] = removeUndefinedFromArrays(formData[k]);
646
+ return obj;
647
+ }, {});
648
+ }
649
+ else if (Array.isArray(formData)) {
650
+ return formData.reduce((filtered, i) => {
651
+ if (i === undefined || i === null || i === "") {
652
+ return filtered;
653
+ }
654
+ filtered.push(removeUndefinedFromArrays(i));
655
+ return filtered;
656
+ }, []);
657
+ }
658
+ return formData;
659
+ };
@@ -77,13 +77,14 @@ class _SchemaField extends React.Component {
77
77
  return Object.assign(Object.assign({}, _props), { uiSchema: Object.assign(Object.assign({}, _props.uiSchema), { "ui:functions": restUiFns }) });
78
78
  }
79
79
  render() {
80
+ var _a;
80
81
  const props = this.applyFunction(this.props);
81
82
  let { schema, uiSchema = {}, formContext, registry } = props, _props = __rest(props, ["schema", "uiSchema", "formContext", "registry"]); // eslint-disable-line @typescript-eslint/no-unused-vars
82
83
  const { formContext: _formContext } = registry;
83
84
  // rjsf displays a duplicate label if 'uniqueItems' is true in some cases. We prevent that here.
84
85
  // Example of when it shows duplicate is http://localhost:8083/?id=JX.652&local=true, "Elinympäristö" on gathering
85
86
  // level.
86
- if (types_1.isJSONSchemaArray(schema) && uiSchema && uiSchema.items && uiSchema.items["ui:field"]) {
87
+ if (types_1.isJSONSchemaArray(schema) && ((_a = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items) === null || _a === void 0 ? void 0 : _a["ui:field"])) {
87
88
  schema = Object.assign(Object.assign({}, schema), { uniqueItems: false });
88
89
  }
89
90
  const options = utils_1.getUiOptions(uiSchema);
@@ -110,7 +110,7 @@ const getChildProps = (props) => {
110
110
  while (d >= 0) {
111
111
  formData[d] = n;
112
112
  if (utils_1.isEmptyString(n)) {
113
- n = undefined; //object keys can't be "", so root key is in childrenMap 'undefined'.
113
+ n = undefined; // object keys can't be "", so root key is in childrenMap 'undefined'.
114
114
  }
115
115
  addSelect(d, n, Object.keys(childrenMap[parentsMap[n]]));
116
116
  d--;
@@ -85,7 +85,7 @@ function SearchableDrowndown(props) {
85
85
  const enumOptions = react_1.useMemo(() =>
86
86
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
87
87
  getEnumOptions(options.enumOptions, uiSchema, includeEmpty), [options.enumOptions, uiSchema, includeEmpty]);
88
- const getLabelFromValue = react_1.useCallback((value) => value !== undefined && value !== ""
88
+ const getLabelFromValue = react_1.useCallback((value) => value !== undefined && value !== "" && value !== null
89
89
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
90
  ? enumOptions.find(item => item.value === value).label
91
91
  : "", [enumOptions]);
package/lib/types.js CHANGED
@@ -6,7 +6,7 @@ function isJSONSchemaObject(schema) {
6
6
  }
7
7
  exports.isJSONSchemaObject = isJSONSchemaObject;
8
8
  function isJSONSchemaArray(schema) {
9
- return schema.type === "object";
9
+ return schema.type === "array";
10
10
  }
11
11
  exports.isJSONSchemaArray = isJSONSchemaArray;
12
12
  function isJSONSchemaEnum(jsonSchema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.59",
3
+ "version": "15.1.60",
4
4
  "description": "React module capable of building dynamic forms from Laji form json schemas",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",