@luomus/laji-form 15.1.71 → 15.1.72

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.
@@ -5,7 +5,7 @@ import { ReactUtilsType } from "../utils";
5
5
  import { Theme } from "../themes/theme";
6
6
  import { ContextProps } from "../ReactContext";
7
7
  import Form from "@rjsf/core";
8
- import { Field, Widget, TemplatesType } from "@rjsf/utils";
8
+ import { Field, Widget, TemplatesType, ErrorSchema } from "@rjsf/utils";
9
9
  import ApiClient, { ApiClientImplementation } from "../ApiClient";
10
10
  import KeyHandlerService, { ShortcutKeys } from "../services/key-handler-service";
11
11
  import SettingsService, { Settings } from "../services/settings-service";
@@ -53,19 +53,21 @@ export interface LajiFormProps extends HasMaybeChildren {
53
53
  onSubmit?: (data: {
54
54
  formData: any;
55
55
  }) => void;
56
- onValidationError?: (extraErrors: any) => void;
56
+ onValidationError?: (extraErrors: ErrorSchema) => void;
57
57
  validators?: any;
58
58
  warnings?: any;
59
59
  onSettingsChange?: (settings: any, global: boolean) => void;
60
60
  mediaMetadata?: MediaMetadata;
61
61
  theme?: Theme;
62
62
  lajiGeoServerAddress?: string;
63
+ extraErrors: ErrorSchema;
63
64
  }
64
65
  export interface LajiFormState {
65
66
  submitHooks?: SubmitHook[];
66
67
  formContext: FormContext;
67
68
  formData?: any;
68
- extraErrors?: any;
69
+ extraErrors?: ErrorSchema;
70
+ externalErrors?: ErrorSchema;
69
71
  error?: boolean;
70
72
  runningSubmitHooks?: boolean;
71
73
  }
@@ -282,7 +282,8 @@ class LajiForm extends React.Component {
282
282
  this.validateAndSubmit = (warnings = true, onlySchema = false) => {
283
283
  const { formData } = this.state;
284
284
  const { onValidationError, onSubmit } = this.props;
285
- return this.validate(warnings, true, onlySchema).then((valid) => {
285
+ this.setState({ externalErrors: undefined });
286
+ return this.validate(warnings, true, onlySchema).then(valid => {
286
287
  if (formData !== this.state.formData) {
287
288
  this.validateAndSubmit(warnings, onlySchema);
288
289
  }
@@ -329,12 +330,15 @@ class LajiForm extends React.Component {
329
330
  this.cachedNonliveValidations = (0, deepmerge_1.default)(schemaErrors, _validations);
330
331
  block && this.memoizedFormContext.services.blocker.pop();
331
332
  }
332
- const merged = (0, deepmerge_1.default)(_liveValidations, !nonlive
333
+ const mergedInternalErrors = (0, deepmerge_1.default)(_liveValidations, !nonlive
333
334
  ? (this.cachedNonliveValidations || {})
334
335
  : (0, deepmerge_1.default)(_validations, schemaErrors));
336
+ const mergedAll = (0, deepmerge_1.default)(this.state.externalErrors || {}, mergedInternalErrors);
335
337
  this.validating = false;
336
- resolve(!Object.keys(merged).length);
337
- !equals((this.state.extraErrors || {}), merged) && this.setState({ extraErrors: merged }, this.popErrorListIfNeeded);
338
+ resolve(!Object.keys(mergedAll).length);
339
+ if (!equals((this.state.extraErrors || {}), mergedAll)) {
340
+ this.setState({ extraErrors: mergedAll }, this.popErrorListIfNeeded);
341
+ }
338
342
  }).catch((e) => {
339
343
  block && this.memoizedFormContext.services.blocker.pop();
340
344
  throw e;
@@ -516,11 +520,16 @@ class LajiForm extends React.Component {
516
520
  if (this.apiClient && "lang" in props && this.props.lang !== props.lang) {
517
521
  this.apiClient.setLang(props.lang);
518
522
  }
519
- this.setState(this.getStateFromProps(props));
523
+ this.setState(this.getStateFromProps(props), this.popErrorListIfNeeded);
520
524
  }
521
525
  getStateFromProps(props) {
526
+ var _a;
522
527
  const state = {
523
- formContext: this.getMemoizedFormContext(props)
528
+ formContext: this.getMemoizedFormContext(props),
529
+ externalErrors: props.extraErrors,
530
+ extraErrors: ((_a = this.state) === null || _a === void 0 ? void 0 : _a.extraErrors)
531
+ ? (0, deepmerge_1.default)(this.state.extraErrors, props.extraErrors || {})
532
+ : props.extraErrors
524
533
  };
525
534
  if (((!this.state && props.schema && Object.keys(props.schema).length) || (this.state && !("formData" in this.state))) || ("formData" in props && props.formData !== this.props.formData)) {
526
535
  state.formData = state.formContext.services.ids.addLajiFormIds((0, utils_1.getDefaultFormState)(props.schema, props.formData, props.schema))[0];
@@ -632,7 +641,7 @@ class LajiForm extends React.Component {
632
641
  showShortcutsButton && this.props.showShortcutButton !== false && shortcuts && (React.createElement(components_1.TooltipComponent, { tooltip: this.getShorcutButtonTooltip() },
633
642
  React.createElement(components_1.Button, { variant: undefined, onClick: this.toggleHelp }, translations.Shortcuts))),
634
643
  React.createElement(components_1.FailedBackgroundJobsPanel, { jobs: this.state.submitHooks, schema: this.props.schema, uiSchema: uiSchema, formContext: this.state.formContext, errorClickHandler: this.memoizedFormContext.services.focus.focus, ref: this.bgJobRef }),
635
- React.createElement(core_1.default, Object.assign({}, this.props, { formData: this.state.formData, uiSchema: uiSchema, ref: this.formRef, onChange: this.onChange, onSubmit: this.onSubmit, fields: this.getFields(this.props.fields), widgets: this.getWidgets(this.props.widgets), templates: this.getTemplates(this.props.templates), formContext: this.state.formContext, validator: validator_ajv6_1.default, noValidate: true, extraErrors: this.state.extraErrors, noHtml5Validate: true, liveValidate: true, autoComplete: "off", tagName: "div", readonly: readonly, disabled: disabled }), this.props.children),
644
+ React.createElement(core_1.default, Object.assign({}, this.props, { formData: this.state.formData, uiSchema: uiSchema, ref: this.formRef, onChange: this.onChange, onSubmit: this.onSubmit, fields: this.getFields(this.props.fields), widgets: this.getWidgets(this.props.widgets), templates: this.getTemplates(this.props.templates), formContext: this.state.formContext, validator: validator_ajv6_1.default, noValidate: true, extraErrors: this.state.extraErrors || {}, noHtml5Validate: true, liveValidate: true, autoComplete: "off", tagName: "div", readonly: readonly, disabled: disabled }), this.props.children),
636
645
  (!this.props.children && this.props.renderSubmit !== false) ? (React.createElement(components_1.Button, { id: "submit", onClick: this.submit, disabled: readonly || disabled }, this.props.submitText || translations.Submit)) : null,
637
646
  shortcuts &&
638
647
  React.createElement(Panel, { ref: this.shortcutHelpRef, className: "shortcut-help laji-form-popped z-depth-3 hidden", style: { top: (this.props.topOffset || 0) + 5, bottom: (this.props.bottomOffset || 0) + 5 }, variant: "info" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.71",
3
+ "version": "15.1.72",
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",