Skip to content

Commit

Permalink
✨ [#2] Add iban component
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Oct 26, 2023
1 parent b12577c commit e9103cf
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/formio/components/iban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {InputComponentSchema, MultipleCapable} from '..';

type Validator = 'required';
type TranslatableKeys = 'label' | 'description' | 'tooltip';

export type IbanInputSchema = InputComponentSchema<string, Validator, TranslatableKeys>;

/**
* @group Form.io components
* @category Base types
*/
export interface BaseIbanComponentSchema extends Omit<IbanInputSchema, 'hideLabel' | 'disabled'> {
type: 'iban';
validateOn?: 'blur';
}

/**
* @group Form.io components
* @category Concrete types
*/
export type IbanComponentSchema = MultipleCapable<BaseIbanComponentSchema>;
1 change: 1 addition & 0 deletions src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './datetime';
export * from './time';
export * from './phonenumber';
export * from './postcode';
export * from './iban';
export * from './licenseplate';
export * from './number';
export * from './file';
Expand Down
2 changes: 2 additions & 0 deletions src/formio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DateTimeComponentSchema,
EmailComponentSchema,
FileComponentSchema,
IbanComponentSchema,
LicensePlateComponentSchema,
NumberComponentSchema,
PhoneNumberComponentSchema,
Expand Down Expand Up @@ -47,6 +48,7 @@ export type AnyComponentSchema =
| FileComponentSchema
| NumberComponentSchema
// special types
| IbanComponentSchema
| LicensePlateComponentSchema
// layout
| ContentComponentSchema;
Expand Down
115 changes: 115 additions & 0 deletions test-d/formio/components/iban.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {expectAssignable, expectNotAssignable} from 'tsd';

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

// minimal textfield component schema
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
});


// multiple false and appropriate default value type
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
multiple: false,
defaultValue: '',
});

// multiple true and appropriate default value type
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
multiple: true,
defaultValue: [''],
});

// full, correct schema
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
// basic tab
label: 'Some IBAN',
key: 'someIban',
description: '',
tooltip: 'A tooltip',
showInSummary: true,
showInEmail: false,
showInPDF: true,
multiple: false,
hidden: false,
clearOnHide: true,
isSensitiveData: true,
defaultValue: '',
// Advanced tab
conditional: {
show: undefined,
when: '',
eq: '',
},
// Validation tab
validate: {
required: false,
plugins: [],
},
translatedErrors: {nl: {required: 'Geef email.'}},
errors: {required: 'Geef email.'},
// registration tab
registration: {
attribute: '',
},
// translations tab in builder form
openForms: {
translations: {
nl: {label: 'foo'},
},
},
// fixed but not editable
validateOn: 'blur',
});

// validateOn not `blur`
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'change',
});

// invalid, multiple true and non-array default value
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
multiple: true,
defaultValue: '',
});

// invalid, multiple false and array default value
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
multiple: false,
defaultValue: [''],
});

// invalid, multiple true and wrong default value in array element
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
multiple: true,
defaultValue: [0],
});

0 comments on commit e9103cf

Please sign in to comment.