Skip to content

Commit

Permalink
Merge pull request #18 from open-formulieren/feature/2-plate-iban
Browse files Browse the repository at this point in the history
✨ [#2] Add `licenseplate` and `iban` component
  • Loading branch information
sergei-maertens authored Oct 27, 2023
2 parents 05ae49a + d6c01f1 commit 619d979
Show file tree
Hide file tree
Showing 6 changed files with 381 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>;
2 changes: 2 additions & 0 deletions src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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
34 changes: 34 additions & 0 deletions src/formio/components/licenseplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {InputComponentSchema, MultipleCapable} from '..';

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

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

/**
* @group Form.io components
* @category Base types
*/
export interface LicensePlateProperties {
type: 'licenseplate';
validate: {
pattern: '^[a-zA-Z0-9]{1,3}\\-[a-zA-Z0-9]{1,3}\\-[a-zA-Z0-9]{1,3}$';
};
validateOn: 'blur';
}

/**
* @group Form.io components
* @category Base types
*/
export type BaseLicensePlateComponentSchema = Omit<
LicensePlateInputSchema,
'hideLabel' | 'placeholder'
> &
LicensePlateProperties;

/**
* @group Form.io components
* @category Concrete types
*/
export type LicensePlateComponentSchema = MultipleCapable<BaseLicensePlateComponentSchema>;
5 changes: 5 additions & 0 deletions src/formio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
DateTimeComponentSchema,
EmailComponentSchema,
FileComponentSchema,
IbanComponentSchema,
LicensePlateComponentSchema,
NumberComponentSchema,
PhoneNumberComponentSchema,
PostcodeComponentSchema,
Expand Down Expand Up @@ -45,6 +47,9 @@ export type AnyComponentSchema =
| PostcodeComponentSchema
| FileComponentSchema
| NumberComponentSchema
// special types
| IbanComponentSchema
| LicensePlateComponentSchema
// layout
| ContentComponentSchema;

Expand Down
129 changes: 129 additions & 0 deletions test-d/formio/components/iban.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {expectAssignable, expectNotAssignable} from 'tsd';

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

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


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

// multiple true and appropriate default value type
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
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 IBAN.'}},
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',
});

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

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

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

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

0 comments on commit 619d979

Please sign in to comment.