Skip to content

Commit

Permalink
Merge pull request #55 from open-formulieren/feature/4546-soft-requir…
Browse files Browse the repository at this point in the history
…ed-validation

Soft required validation
  • Loading branch information
sergei-maertens authored Oct 15, 2024
2 parents 24f430b + 03f1bc1 commit af6f89c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/formio/components/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface FileUploadConfiguration {
export interface BaseFileComponentSchema
extends Omit<StrictComponentSchema<FileUploadData[]>, UnusedFileProperties | 'errors'>,
DisplayConfig,
Omit<OFExtensions<TranslatableKeys>, 'registration'>,
Omit<OFExtensions<TranslatableKeys, {softRequired?: boolean}>, 'registration'>,
HasValidation<Validator> {
validate?: OFValidateOptions<Validator>;
type: 'file';
Expand Down
1 change: 1 addition & 0 deletions src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export * from './password';
export * from './content';
export * from './columns';
export * from './fieldset';
export * from './softRequiredErrors';
45 changes: 45 additions & 0 deletions src/formio/components/softRequiredErrors.ts
Original file line number Diff line number Diff line change
@@ -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<never>,
| 'conditional'
| 'tooltip'
| 'multiple'
| 'defaultValue'
| 'clearOnHide'
| 'validate'
| 'errors'
| 'description'
| 'hidden'
| 'hideLabel'
| 'disabled'
| 'widget'
| 'validateOn'
| 'placeholder'
>,
Omit<OFExtensions<TranslatableKeys>, 'registration' | 'isSensitiveData'> {
id: string;
key: string;
type: 'softRequiredErrors';
/**
* Even though the label is present, it is typically not displayed anywhere.
*/
html: string;
label?: string;
}
2 changes: 2 additions & 0 deletions src/formio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
SelectComponentSchema,
SelectboxesComponentSchema,
SignatureComponentSchema,
SoftRequiredErrorsComponentSchema,
TextFieldComponentSchema,
TextareaComponentSchema,
TimeComponentSchema,
Expand Down Expand Up @@ -85,6 +86,7 @@ export type AnyComponentSchema =
| ContentComponentSchema
| ColumnsComponentSchema
| FieldsetComponentSchema
| SoftRequiredErrorsComponentSchema
// deprecated
| PostcodeComponentSchema
| PasswordComponentSchema
Expand Down
3 changes: 2 additions & 1 deletion test-d/formio/components/file.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ expectAssignable<FileComponentSchema>({
docVertrouwelijkheidaanduiding: 'openbaar',
titel: '',
},
// translations tab in builder form
// (mostly) translations tab in builder form
openForms: {
softRequired: true,
translations: {
nl: {
label: 'Bestand toevoegen',
Expand Down
28 changes: 28 additions & 0 deletions test-d/formio/components/softRequiredErrors.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {expectAssignable} from 'tsd';

import {SoftRequiredErrorsComponentSchema} from '../../../lib';

// Minimal schema
expectAssignable<SoftRequiredErrorsComponentSchema>({
type: 'softRequiredErrors',
id: 'iitral8',
key: 'someKey',
label: 'Ignored',
html: '<div>Will need to be properly {{ field_errors }} structured.</div>',
});

// With translations
expectAssignable<SoftRequiredErrorsComponentSchema>({
type: 'softRequiredErrors',
id: 'iitral8',
key: 'someKey',
label: 'Ignored',
html: '<div>Will need to be properly {{ field_errors }} structured.</div>',
openForms: {
translations: {
nl: {
html: '<div>NL translation</div>',
},
},
},
});

0 comments on commit af6f89c

Please sign in to comment.