From f209c49e195e4f7066757cac9ef3d0287fd7db0d Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 14 Oct 2024 08:42:11 +0200 Subject: [PATCH 1/2] :label: [open-formulieren/open-forms#4546] Add softRequired extension to file component --- src/formio/components/file.ts | 2 +- test-d/formio/components/file.test-d.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/formio/components/file.ts b/src/formio/components/file.ts index 5aa9bd1..df67a02 100644 --- a/src/formio/components/file.ts +++ b/src/formio/components/file.ts @@ -79,7 +79,7 @@ export interface FileUploadConfiguration { export interface BaseFileComponentSchema extends Omit, UnusedFileProperties | 'errors'>, DisplayConfig, - Omit, 'registration'>, + Omit, 'registration'>, HasValidation { validate?: OFValidateOptions; type: 'file'; diff --git a/test-d/formio/components/file.test-d.ts b/test-d/formio/components/file.test-d.ts index f532b4b..301a2c3 100644 --- a/test-d/formio/components/file.test-d.ts +++ b/test-d/formio/components/file.test-d.ts @@ -215,8 +215,9 @@ expectAssignable({ docVertrouwelijkheidaanduiding: 'openbaar', titel: '', }, - // translations tab in builder form + // (mostly) translations tab in builder form openForms: { + softRequired: true, translations: { nl: { label: 'Bestand toevoegen', From 03f1bc1b05d563dd20b62965fb5eac20e08c196a Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 14 Oct 2024 09:23:13 +0200 Subject: [PATCH 2/2] :sparkles: [open-formulieren/open-forms#4546] Add softrequired validation errors display component --- src/formio/components/index.ts | 1 + src/formio/components/softRequiredErrors.ts | 45 +++++++++++++++++++ src/formio/index.ts | 2 + .../components/softRequiredErrors.test-d.ts | 28 ++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/formio/components/softRequiredErrors.ts create mode 100644 test-d/formio/components/softRequiredErrors.test-d.ts diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index 68f6620..eb4900f 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -30,3 +30,4 @@ export * from './password'; export * from './content'; export * from './columns'; export * from './fieldset'; +export * from './softRequiredErrors'; diff --git a/src/formio/components/softRequiredErrors.ts b/src/formio/components/softRequiredErrors.ts new file mode 100644 index 0000000..665bcd7 --- /dev/null +++ b/src/formio/components/softRequiredErrors.ts @@ -0,0 +1,45 @@ +import {LayoutComponentSchema, OFExtensions} from '..'; + +type TranslatableKeys = 'html'; + +/** + * The softRequiredErrors component schema. It's a variation on the WYSIWYG content + * component. + * + * Any validation errors related to soft-required fields (the fields are required but + * don't block progressing in the form and are therefore mostly informational/warnings) + * are displayed here. The form designer can control the body text, and the SDK will + * then interpolate the actual field labels that violate the requirement(s). If there + * are no errors, the component is not to be displayed. + * + * @group Form.io components + * @category Concrete types + */ +export interface SoftRequiredErrorsComponentSchema + extends Omit< + LayoutComponentSchema, + | 'conditional' + | 'tooltip' + | 'multiple' + | 'defaultValue' + | 'clearOnHide' + | 'validate' + | 'errors' + | 'description' + | 'hidden' + | 'hideLabel' + | 'disabled' + | 'widget' + | 'validateOn' + | 'placeholder' + >, + Omit, 'registration' | 'isSensitiveData'> { + id: string; + key: string; + type: 'softRequiredErrors'; + /** + * Even though the label is present, it is typically not displayed anywhere. + */ + html: string; + label?: string; +} diff --git a/src/formio/index.ts b/src/formio/index.ts index 0eea2b7..521d749 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -26,6 +26,7 @@ import { SelectComponentSchema, SelectboxesComponentSchema, SignatureComponentSchema, + SoftRequiredErrorsComponentSchema, TextFieldComponentSchema, TextareaComponentSchema, TimeComponentSchema, @@ -85,6 +86,7 @@ export type AnyComponentSchema = | ContentComponentSchema | ColumnsComponentSchema | FieldsetComponentSchema + | SoftRequiredErrorsComponentSchema // deprecated | PostcodeComponentSchema | PasswordComponentSchema diff --git a/test-d/formio/components/softRequiredErrors.test-d.ts b/test-d/formio/components/softRequiredErrors.test-d.ts new file mode 100644 index 0000000..570a7c9 --- /dev/null +++ b/test-d/formio/components/softRequiredErrors.test-d.ts @@ -0,0 +1,28 @@ +import {expectAssignable} from 'tsd'; + +import {SoftRequiredErrorsComponentSchema} from '../../../lib'; + +// Minimal schema +expectAssignable({ + type: 'softRequiredErrors', + id: 'iitral8', + key: 'someKey', + label: 'Ignored', + html: '
Will need to be properly {{ field_errors }} structured.
', +}); + +// With translations +expectAssignable({ + type: 'softRequiredErrors', + id: 'iitral8', + key: 'someKey', + label: 'Ignored', + html: '
Will need to be properly {{ field_errors }} structured.
', + openForms: { + translations: { + nl: { + html: '
NL translation
', + }, + }, + }, +});